laravel

Laravel conditionally add global scopes after method boot

好久不见. 提交于 2021-01-29 06:50:15
问题 Is it possible to add a global scope after the model has already passed the constructor? I would like to catch an event (for example creating ) and attach a global scope only if the model is creating. So far I've done: Event::listen('eloquent.creating*', function ($event, $model) { /** * @var Model $eloquentModel */ $eloquentModel = $model[0]; $eloquentModel->addGlobalScope(new AuthorizationScope($event)); }); The scope constructor is called, but the apply method from it is never fired

I get an Nginx 503 error when using Laradock to deploy a Laravel App

假如想象 提交于 2021-01-29 06:28:14
问题 Months ago I deployed a Laravel app ( laravel1 ) using Laradock and Jwilder Nginx Proxy. Recently I tried to deploy a second Laravel app ( laravel2 ), by using the same configuration values in both .env and docker-compose.yml files. However, I am getting the Nginx 503 error: 503 Service Temporarily Unavailable / Nginx To give more context, this is the structure of my directories, where Laravel1 is the first app I deployed which is currently working fine, and Laravel2 which has the 503 error.

Laravel Blade : Checkbox sends 'null' value to database

|▌冷眼眸甩不掉的悲伤 提交于 2021-01-29 06:14:59
问题 I don't get it. My Checkbox sends a 'null' value back to my controller when checked. If it is in the DB it will come back checked, but the moment I uncheck it, and then check it again, my form sends a 'null' value What am I doing wrong? <div class="col"> <input type="checkbox" name="staff" @if($child->staff == 'true') checked @endif > </div> 回答1: The checked attribute just determines whether or not the checkbox should be included in the post request. The value attribute determines what the

Laravel REST API and frontend

别等时光非礼了梦想. 提交于 2021-01-29 06:08:23
问题 I created a project in Laravel, small database and added REST API in laravel to connect mobile app with database. What should I use to get data from database in web application? Using laravel models is easy but is that a good way to create another controllers to handle forms etc instead using rest api controllers? Thanks 回答1: Laravel also support for Restful API in own way. for this you create your controller in Api folder: php artisan make:controller Api/TestController define your routes in

Resource Controller methods with model as parameter not working

两盒软妹~` 提交于 2021-01-29 05:56:46
问题 As in the basic Laracasts.com tutorial (Laracast 5.7 from scratch) I'm trying to use the following methods public function show(prototypes $prototypes) parameter to construct a view. However my view is created correctly but $prototypes is null. The route works well( /prototypes/1/edit ) and I ensured that a prototype object with the id 1 exists. I found some older solution which stated to use something like (integer $id) as parameter but this leads to some more code. It should work like this:

Laravel - Filter a collection by a dynamic field

可紊 提交于 2021-01-29 05:43:53
问题 The model has 3 fields that are attributes of the model and the 4th field is a dynamic field that is called "fullTitle" [ { "id": 1, "hours": 2000, "car_id": 3, "fullTitle": "Test", } } <?php namespace App; use App\Car; class VenderModel extends Model { use TranslationTrait; protected $guarded = ['*']; /** * The accessors to append to the model's array form. * * @var array */ protected $appends = [ 'fullTitle' ]; /** * Accessor for dynamic property fullTitle to use as selector name. * @param

Laravel upload multiple files

本小妞迷上赌 提交于 2021-01-29 05:40:19
问题 I'm building a gallery with multiple files functionality. So far I'm having two issues, but let's paste my code first. Controller: public function store(Request $request) { $gallery = new GalleryImage(); if($request->hasFile('image')) { $images = $request->file('image'); foreach($images as $image) { $path = $image->getClientOriginalName(); $name = time() . '-' . $path; $gallery->image = $image->move(public_path().'/uploads/temp/', $name); //$gallery->image = $request->file('image')->storeAs(

Invalid input syntax for type timestamp: “NOW() - INTERVAL '12 hours'”

人盡茶涼 提交于 2021-01-29 05:31:38
问题 I'm trying to make a query based on a field ``time` to get the last week data: Measure::where('time', '>', "NOW() - INTERVAL '12 hours'")->get(); but I can't make it work. I get this message: SQLSTATE[22007]: Invalid datetime format: 7 ERROR: invalid input syntax for type timestamp: "NOW() - INTERVAL '12 hours'" (SQL: select * from "measures" where "time" > NOW() - INTERVAL '12 hours') Thing is I get this condition from official docs of timescaleDB, supposed to be postgres compatible: SELECT

How do I use components to display my dynamic navigation bar using laravel?

不羁的心 提交于 2021-01-29 05:17:33
问题 I have an issue where I can't display my navigation bar when I am displaying my page content. Currently the output of my code is, Undefined variable: navContent (View: C:\Users\Computer Angel\Documents\blog\resources\views\layouts\components\navbar.blade.php). My desired output is to show my navigation bar, then my page content below it. This is my code for the dynamic.blade.php which is where both the navigation bar and the page content should be displayed. <!DOCTYPE html> <html> <head> <

Limiting the result of nested relationship in Laravel

末鹿安然 提交于 2021-01-29 05:12:15
问题 I have a nested relationship that I want to set a condition and a limit. $data = Accommodation::with('accommodationFacilities', 'city') ->take(10) ->with('accommodationRooms.roomPricingHistory') ->limit(2) ->where('is_deleted', 0) ->paginate(10); Now I have a nested relation on line 2 that I want to limit this relation by: roomPricingHistory . The code limits the parent relation which is: accommodationRooms . Any idea how I can limit the child relation and how can I set an if for it so if a