laravel tricks and tips

Solutions on MaxInterview for laravel tricks and tips by the best coders in the world

showing results for - "laravel tricks and tips"
Alex
17 Sep 2018
1Route::get('orders', function()
2{
3    return View::make('orders.index')
4        ->with('orders', Order::all());
5});
6//@sujay
Elisa
28 Aug 2019
1Route::get('logout', function()
2{
3    Auth::logout();
4     
5    return Redirect::home();
6});
7//@sujay
Lennart
01 Jun 2020
1Article::find($article_id)->increment('read_count');
2Article::find($article_id)->increment('read_count', 10); // +10
3Product::find($produce_id)->decrement('stock'); // -1
4//@sujay
Noan
11 May 2020
1{{ Form::model($order) }}
2    <div>
3        {{ Form::label('title', 'Title:') }}
4        {{ Form::text('title') }}
5    </div>
6 
7    <div>
8        {{ Form::label('description', 'Description:') }}
9        {{ Form::textarea('description') }}
10    </div>
11{{ Form::close() }}
12//@sujay
Alessia
18 Oct 2020
1//$user = User::find($id);
2//if (!$user) { abort (404); }
3//=> do this
4$user = User::findOrFail($id);
5//@sujay
Amelia
31 Nov 2017
1$user = [
2    'email' => 'email',
3    'password' => 'password'
4];
5 
6if (Auth::attempt($user))
7{
8    // user is now logged in!
9    // Access user object with Auth::user()
10}
11//@sujay