web cheatsheet.md 1/15/2022
Cheatcheat web
Table of content
Including files
Routes
Controller
Yield
Routes & Yield
Databases
Models
Forms
Cookies
Sessions
API (JS)
including files
add css file to blade:
<link href="{{ asset('css/reset.css') }}" rel="stylesheet">
<link href="{{ asset('css/screen.css') }}" rel="stylesheet">
add script to blade (in body bottom)
<script src="{{ asset('js/script.js') }}"></script>
String concatenation:
<img src="{{ asset('media/' . $product -> id . '.png') }}" alt="image of product">
Routes
Routes(web.php) normal:
,web cheatsheet.md 1/15/2022
Route::get('/', function () {
return view('master');
});
Routes(web.php) through controller:
Route::get('/', [BookingController::class, "index"]);
Route::post('/summary', [ControllerName::class, "displaySummary"])
-> name("summary");
include "use \App\Http\Controllers\ControllerName;" at top of web.php
Route function
in blade:
@foreach($products as $product)
<li><a href="{{ route('details', $product -> id ) }}">{{ $product -> name }}
</a></li>
@endforeach
in web.php
Route::get('/products/101', [StoreController::class, "displayIphone"])
->name('101');
Controller
make a new controller:
go to project directory
php artisan make:controller MyController
simple route in controller:
, web cheatsheet.md 1/15/2022
function index() {
return view("master");
}
Yield
ex in master blade:
@yield("view-content")
ex in other blade file:
@extends("master")
@section("view-content")
<h2>Product catalog</h2>
<ul>
<li><a href="#">Apple Iphone 12</a></li>
<li><a href="#">Samsung S21</a></li>
<li><a href="#">LG OLED TV</a></li>
</ul>
@endsection
So now just simply choose which blade you want to use (not the master blade)
Routes & Yield
Make a url that leads to another page:
<li><a href="{{ url('iphone') }}">Apple Iphone 12</a></li>
in web.php it will look like
Route::get('/iphone', [StoreController::class, "displayIphone"]);
Cheatcheat web
Table of content
Including files
Routes
Controller
Yield
Routes & Yield
Databases
Models
Forms
Cookies
Sessions
API (JS)
including files
add css file to blade:
<link href="{{ asset('css/reset.css') }}" rel="stylesheet">
<link href="{{ asset('css/screen.css') }}" rel="stylesheet">
add script to blade (in body bottom)
<script src="{{ asset('js/script.js') }}"></script>
String concatenation:
<img src="{{ asset('media/' . $product -> id . '.png') }}" alt="image of product">
Routes
Routes(web.php) normal:
,web cheatsheet.md 1/15/2022
Route::get('/', function () {
return view('master');
});
Routes(web.php) through controller:
Route::get('/', [BookingController::class, "index"]);
Route::post('/summary', [ControllerName::class, "displaySummary"])
-> name("summary");
include "use \App\Http\Controllers\ControllerName;" at top of web.php
Route function
in blade:
@foreach($products as $product)
<li><a href="{{ route('details', $product -> id ) }}">{{ $product -> name }}
</a></li>
@endforeach
in web.php
Route::get('/products/101', [StoreController::class, "displayIphone"])
->name('101');
Controller
make a new controller:
go to project directory
php artisan make:controller MyController
simple route in controller:
, web cheatsheet.md 1/15/2022
function index() {
return view("master");
}
Yield
ex in master blade:
@yield("view-content")
ex in other blade file:
@extends("master")
@section("view-content")
<h2>Product catalog</h2>
<ul>
<li><a href="#">Apple Iphone 12</a></li>
<li><a href="#">Samsung S21</a></li>
<li><a href="#">LG OLED TV</a></li>
</ul>
@endsection
So now just simply choose which blade you want to use (not the master blade)
Routes & Yield
Make a url that leads to another page:
<li><a href="{{ url('iphone') }}">Apple Iphone 12</a></li>
in web.php it will look like
Route::get('/iphone', [StoreController::class, "displayIphone"]);