Laravel Cheat Sheet: by Via
Laravel Cheat Sheet: by Via
Laravel Cheat Sheet: by Via
}); // SELECT
Prefixs $users = DB::table('users')->get();
Route::group(array('prefix' => 'admin'), function(){ $users = DB::table('users')->find(2);
// Route:: ... $users = DB::table('users')->where('id',2)->get();
// Route:: ... $users = DB::table('users')->where(array('id' => 2, 'email' =>
}); '[email protected]'))->get();
$users = DB::table('users')->where('id',2)->orWhere('id', 3)->get();
Blade functions $users = DB::table('users')->where(array('id' => 2, 'email' =>
'[email protected]'))->get();
@if(count($posts))
$users = DB::table('users')->where('id', '>', 1)->orderBy('id', 'asc')-
@foreach($posts as $post) >take(2)->skip(2)->get();
<p>{{{ $post->title }}} </p>
$users = DB::table('users')->join('posts', 'users.id', '=', 'posts.user_id')-
@endforeach >get();
@endif // Log
dd(DB::getQueryLog());
Blade Layout // INSERT
$data = array(
<!-- HTML -->
'email' => '[email protected]',
@include('partials.menu');
'password' => '123456'
[...]
);
@yield('content');
DB::table('users')->insert($data);
[...]
// UPDATE
@section('sidebar');
$data = array(
[...]
'email' => '[email protected]',
@show
'password' => 'abc'
);
Blade Template
DB::table('users')->where('email', $data['email'])->update($data);
@extends('layouts.default'); // DELETE
@section('content'); DB::table('users')->where('email', '[email protected]')->delete();
[...]
@stop Eloquent ORM
@section('sidebar')
// SELECT
@parent
$posts = Post::all();
[...]
$posts = Post::find(2);
@stop
$posts = Post::where('title', 'LIKE', '%et%')->get();
$posts = Post::where('title', 'LIKE', '%et%')->take(1)->skip(1)->get();
// INSERT
$post = new Post;
$post->title = 'post1 title';
$post->body = 'post1 body';
$post->save();
// Insert amb vector de dades
$data = array(
'title' => 'post2 title',
'body' => 'post2 body'
);
Post::create($data);
// UPDATE
$post = Post::find(1);
$post->title('updated title');
$post->save();
// DELETE
$post = Post::find(1);
$post->delete();