laravel

Mass assignment won't handle Null input even when default is set on migration.Any solution to this?

﹥>﹥吖頭↗ 提交于 2021-01-28 07:34:26
问题 I have been using mass assignment a lot. I recently came across this issue, where I create fillable, and also defaults for null values, but on using mass assignment, if my inputs are empty, it returns a "Cannot Be Null" Error. My Model protected $fillable = ['name','status']; My Controller $this->model->create($request->all()); My Migration $table->boolean('status')->default(0); Shouldn't the above mean that when I provide nothing on the input field status , it should default to 0? But column

Mass assignment won't handle Null input even when default is set on migration.Any solution to this?

拜拜、爱过 提交于 2021-01-28 07:25:24
问题 I have been using mass assignment a lot. I recently came across this issue, where I create fillable, and also defaults for null values, but on using mass assignment, if my inputs are empty, it returns a "Cannot Be Null" Error. My Model protected $fillable = ['name','status']; My Controller $this->model->create($request->all()); My Migration $table->boolean('status')->default(0); Shouldn't the above mean that when I provide nothing on the input field status , it should default to 0? But column

Get all records of relationship when parent doesn't exist

試著忘記壹切 提交于 2021-01-28 07:13:04
问题 I have two models. Resource: public function account() { return $this->belongsTo('App\Account'); } Account: public function resources() { return $this->hasMany('App\Resource'); } I want to receive all resources of an account knowing user_id from account Model. Account::where('user_id', Auth::id())->first()->resources()->get(); This works only when account exists. It throws error otherwise: Call to a member function resources() on null . What's the smart way to get all resources in Eloquent?

How to update variable on a foreach in blade laravel with js

僤鯓⒐⒋嵵緔 提交于 2021-01-28 07:09:09
问题 I have a page which loads both folders and files available on my database : Like you can see in the picture, files loaded on a first time load all the files availables on all folders with the following code : public function index(){ $folders = Folder::where('user_id', '=', auth()->id())->get(); $data = collect(); $filator = collect(); // loop around the folders foreach ($folders as $f){ $files = DB::table('files') ->where("folder_id",'=',$f->id)->count(); // loop around the files in all

Pass variable from one method to another in same controller Laravel

馋奶兔 提交于 2021-01-28 07:05:31
问题 I need to pass select option value from store method to show i need to pass the $typeg value to show method public function store(Request $request ) { $typeg = $request->input('type'); } public function show($id) { dd($this->store($typeg)); } i get Undefined variable: or Too few arguments to function app\Http\Controllers\appController::show(), 1 passed and exactly 2 expected 回答1: Store your data on session (or somewhere else like cookie, cache, database). So you can reach the data later.

Laravel Echo Client cannot be authenticated

你离开我真会死。 提交于 2021-01-28 06:34:52
问题 I see this question has been asked multiple times, but non of the answers are working so I am asking for help and some insight with it. I am using laravel echo and redis for broadcasting events. My laravel echo server stars up nicely, redis is running nicely. When I reload my webpage I get this error in the laravel-echo server terminal: ⚠ [4:49:19 PM] - qg4WSWl5YusQY8hJAAAA could not be authenticated to private-test-channel.1 {"error":"Unauthenticated."} Client can not be authenticated, got

How to pass a CSRF token safely to a separate VueJS frontend?

纵然是瞬间 提交于 2021-01-28 06:29:34
问题 Laravel(backend) and VueJS(frontend created with Vue CLI) are separated, hence have different domains and repositories. I am wondering what is the best way to pass a CSRF token from Laravel to VueJS safely . I've found some old questions here and on Laracasts but they are either irrelevant, outdated or have no answer. Here are a few: Pass csrf token from Laravel to Vue Creating a sign up token for Laravel app from separate frontend app (Laracasts forum) CSRF in separate angular app I am aware

Laravel merge two columns when querying LIKE

柔情痞子 提交于 2021-01-28 06:08:31
问题 I have a search input ?search=xxxx I have two columns in my database first_name and last_name . I want the search to work for both of them, for example if my input is John Smith the search should be like CONCAT(first_name, last_name) ILIKE %input% But laravel doesn't let me do it: $customers = $customers->selectRaw("CONCAT('first_name', 'last_name') AS fullname")->where("fullname", "ilike", "%" . $text . "%"); Customers is already defined, and is an ORM object, not collection. And the error i

Laravel app.js Conflicts with Datatables

不打扰是莪最后的温柔 提交于 2021-01-28 06:07:11
问题 I am using datatables on a laravel project. But seems like laravels' app.js is conflicting with datatables.min.js I get this error in console. Uncaught TypeError: $(...).DataTable is not a function If I remove app.js from head everything works relation to datatables but then bootstraps menu dropdowns and some other js related stuff stops working obviously because I remove app.js How can I resolve this by including both in head section? UPDATE: Here is head section of my laravel app. Laravel

ajax post with laravel 5.6

我们两清 提交于 2021-01-28 06:03:00
问题 I can't figure out how to get this ajax request to post. <button class="btn btn-sm btn-primary" id="ajaxSubmit">Submit</button> <textarea rows="4" class="form-control resize_vertical" id="application_notes" name="application_notes" placeholder="Notes">{{$application->notes}}</textarea> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script> var url = "/instructor-notes-save/{{$application->id}}" $(document).ready(function(){ $('#ajaxSubmit').click