Skip to content
Advertisement

Using Laravel whenLoaded() deeper than one level

How do I use whenLoaded() for deeper than one level relations? It seems as if one can only use whenLoaded with the first relation depth like this: But then Laravel, if origin is loaded, but not season, Laravel will load it, which creates an N+1 problem. Both origin and season relationships are conditional, and not always used. Therefor I want

How to add custom field in default registration form of Laravel 5.6?

In one of my Laravel 5.6 applications, I need to add a few more fields in the default registration form. So I’ve added only one field to test [phone_no] in the default registration form registration.blade.php, and also add phone_no RegisterController, but when I click on the register button it shows the following errors: So here is the migration file code:

Time format in laravel migration?

I want to have an input, where you put a time in EU format like 12:00 or 21:34. (hh:mm) How do I do that? This is what I have, but it’s obviously wrong. Answer In laravel 5.6 you have this new feature that you can cast your timestamp so your migration should be like this And in your Post model

number_format() php remove trailing zeros

Is there a way with number_format() to leave out decimal places if the number is not a float/decimal? For example, I would like the following input/output combos: 50.8 => 50.8 50.23 => 50.23 …

Laravel eloquent model Class not found

This is my web.php in routes folder Route::get(‘/task’,function(){ $task = AppTask::all(); return view(‘task’,[‘task’ => $task]); }); This is my Task model, Task.php <…

Advertisement