Laravel Flashcards
How do you iterate through an array (e.g. users) to print one of its contents (e.g. name) on screen as a list?
@foreach($users as $user)
<li>{{ $user[‘name’] }}</li>
@endforeach
Start Laravel Sail without blocking the console!
sail up -d
Make the /contact page path that displays the contact.blade.php page!
in web.php:
Route::get(‘/contact’, function () {
return view(‘contact’);
});
Where would you need to store a layout file to be easily usable?
resources -> views -> components
Implement the usage of a script called “nav-bar.blade.php”!
<x-nav-bar>
</x-nav-bar>
How could you check if the page path (for example /about) is the current page path?
request().is(‘about’)
Throw the right error for when a user tries to access a non-existent page!
abort(404);
How can you create a new migration using artisan?
php artisan make:migration
Which artisan command gives you the opportunity to then modify the database of a project in said terminal?
sail artisan tinker
Given the fact, that a class People (in App\Models\People) accesses a database, which saves the names (name), the way they usually greet people (greetings) and their age (age), give an example for how to add somebody in the terminal using artisan!
App\Models\People::create([‘name’ => ‘xx’, ‘greeting’ => ‘xx’, ‘age’ => ‘xx’])
Using artisan, what do you need to make to create something that can generate data for a database?
A factory
An employer (the class is called Employer) can have many job listings but a job listing is only going to be under one employer. How could you test if $this is from an employer?
$this->belongsTo(Employer:class)
Access the first object out of a database called Employer(App\Models\Employer)!
App\Models\Employer::first();
If you run something in artisan tinker, it fails, you fix the cause of the failure in the code and then run the function again right away within tinker it will fail again. What causes this?
Once artisan tinker gets run, the program gets loaded into memory and changes only apply once you close out of and restart tinker, without said restart the bug still exists within tinker and that will cause the failure.
Import App\Models\People in PHP!
use App\Models\People;