6. Working With the Query Builder

Descripción

(Laravel) Laravel 5.4 From Scratch Diapositivas sobre 6. Working With the Query Builder, creado por mohammed al-obadi el 08/10/2017.
mohammed al-obadi
Diapositivas por mohammed al-obadi, actualizado hace más de 1 año
mohammed al-obadi
Creado por mohammed al-obadi hace alrededor de 7 años
9
0

Resumen del Recurso

Diapositiva 1

    6. Working With the Query Builder
    php artisan make:migration create_tasks_table php artisan make:migration create_tasks_table --create=tasks $table->increments('id'); $table->integer('user_id'); $table->text('body'); $table->timestamps(); If a mistake happened in a schema of a migration file, just edit it and issue: `php artisan migrate:refresh`  

Diapositiva 2

    Laravel query builder: https://laravel.com/docs/5.5/queries This line reads all the records from the table "tasks" from the database.$tasks = DB::table('tasks')->get(); - - - - - - - - - - If you return the result in a route function: $tasks = DB::table('tasks')->get(); return $tasks; You will get a JSON formate of the table data printed into the browser. Can help in inspecting the structure of the table. Install JSON formatter extension into Google chrome. - - - - - - - - - - If you return it to the view: $tasks = DB::table('tasks')->get(); return view('welcome', compact('tasks')); You will need to read it something like this:  Note that this time $tasks is a collection of objects (not an array) so to access it, you need this syntax $task->body <ul>     @foreach ($tasks as $task)        <li>{{$task->body}}</li>     @endforeach </ul>   - - - - - - - - - - Now try this: Route::get('/tasks/{id}', function ($id) {     $task = DB::table('tasks')->where('id', '=', $id)->get();          dd($id); // dump and die   }); You access this route this way: http://localhost:8000/tasks/1  

Diapositiva 3

    Intoduction to views that are created into folders inside the views folder and how to refer to them in the route. For example; to access this view file: "views/tasks/show.blade.php" Inside the route, you return:return view('tasks.show', ['task' => $task]); You can use dot 'tasks.show' or slash 'tasks/show' 'tasks\show'  - - - - - - - - - - // This corresponds to "views/tasks/show.index.php"Route::get('/tasks', function () {     $tasks = DB::table('tasks')->get();     return view('tasks.index', ['tasks' => $tasks]); }); Inside the view "views/tasks/show.ndex.php": <ul>     @foreach ($tasks as $task)     <li><a href="tasks/{{$task->id}}">{{$task->body}}</a></li>     @endforeach </ul> - - - - - - - - - - // This corresponds to "views/tasks/show.blade.php"Route::get('/tasks/{id}', function ($id) {        $task = DB::table('tasks')->find($id);     return view('tasks.show', ['task' => $task]); }); Inside the view: {{ $task->body }}  
Mostrar resumen completo Ocultar resumen completo

Similar

2. Basic Routing and Views
mohammed al-obadi
1. Laravel Installation and Composer
mohammed al-obadi
PHP/Laravel
Ahmed Salem
PHP/Laravel
Ahmed Salem
PHP/Laravel
BERBAGI ILMU
4. Database Setup and Sequel Pro
mohammed al-obadi
3. Laravel Valet is Your Best Friend
mohammed al-obadi
Primera Guerra Mundial.
Oswaldo Martinez
flash cards vocabulario inglés
Michael Villalobos
SEIS ESTRATEGIAS PARA MEJORAR LA COMPRENSIÓN LECTORA
lupitta_12
ESPAÑA FÍSICA: TERMOS
Nuria Prado Álvarez