Skip to content

Instantly share code, notes, and snippets.

@yavgel85
Last active June 1, 2021 07:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yavgel85/ea04de11952827656d8a5558d627244b to your computer and use it in GitHub Desktop.
Save yavgel85/ea04de11952827656d8a5558d627244b to your computer and use it in GitHub Desktop.
Shorter and more readable syntax #laravel #bestpractices
Common syntax Shorter and more readable syntax
Session::get('cart') session('cart')
$request->session()->get('cart') session('cart')
Session::put('cart', $data) session(['cart' => $data])
$request->input('name'), Request::get('name') $request->name, request('name')
return Redirect::back() return back()
is_null($obj->relation) ? null : $obj->relation->id optional($obj->relation)->id
return view('index')->with('title', $title)->with('client', $client) return view('index', compact('title', 'client'))
request->has('value') ? request->value : 'default' request->get('value', 'default')
Carbon::now(), Carbon::today() now(), today()
App::make('Class') app('Class')
->where('column', '=', 1) ->where('column', 1)
->orderBy('created_at', 'desc') ->latest()
->orderBy('age', 'desc') ->latest('age')
->orderBy('created_at', 'asc') ->oldest()
->select('id', 'name')->get() ->get(['id', 'name'])
->first()->name ->value('name')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment