New answers tagged

2

Not sure that it makes much difference, but I find this simpler class PageController extends Controller { public function page1() { return view('page', [ 'page' => [ 'slug' => 'page-1', 'title' => 'Page 1', 'content' => 'Content..', ] ]); } public function page2() { return view('page', [ 'page' ...


0

You could try something like this: private function applyFiltering($query, $request) { $query->when($request->has('active_group'), function($query) use($request) { $query->whereNotIn('status_id', [1, 6, 4]); $query->whereHas('userStatus', function ($query) use ($request) { $query->where('user_id', $request->...


1

It's a correct way to do it like this. Few suggestions: Add validation before creating user. You don't want to fail on save for duplicate user email. For better UX if you can it's a good idea to do it even before form submit (with ajax request when email field is changed). If your app has more user related things like user profile, user control panel I ...


4

"Premature optimization is the root of all evil." As long as this code works and causes no problem, nothing should be really done. Trying to "improve" it, most likely you will cause a severe harm to readability, maintainability and - ironically - performance. The only thing could be suggested out of the blue is to wrap the loop in a transaction. It will ...


Top 50 recent answers are included