Skip to content

Instantly share code, notes, and snippets.

View nicolaskempf57's full-sized avatar

Nicolas KEMPF nicolaskempf57

View GitHub Profile
@nicolaskempf57
nicolaskempf57 / 01-minimal.html
Last active October 29, 2021 06:43
Initiation au HTML
<!DOCTYPE html>
<html lang="fr">
<head>
<title>Le titre</title>
</head>
<body>
<!-- contenu de la page -->
</body>
</html>
<?php
DB::select('select * from users where votes = ?', [100]);
DB::select('select * from users where votes = :votes', ['votes' => 1]);
DB::table('users')
->where('votes', '=', 100)
->get();
User::where('votes', '=', 100)
->get();
<?php
use App\Http\Controllers\LocationsController;
use Illuminate\Http\Request;
Route::get('/locations/{location:slug}', [LocationsController::class, 'show'])
->name('locations.view')
->missing(function (Request $request) {
return Redirect::route('locations.index');
});
<?php
// routes
use App\Models\Post;
Route::get('/posts/{post:slug}', function (Post $post) {
return $post;
});
// ou dans votre modèle
public function getRouteKeyName()
<?php
use App\Models\User;
Route::get('/users/{user}', function (User $user) {
return $user->email;
});
<?php
Route::get('/path/{start?}/{end?}', function ($start = null, $end = null)
{
if (!$start) {
// set start
}
if (!$end) {
// set end
}
@nicolaskempf57
nicolaskempf57 / 1-route-parameter.php
Last active February 11, 2022 10:53
Laravel Basics 2 : route parameter
<?php
use Illuminate\Http\Request;
Route::get('/user/{id}', function (Request $request, $id) {
return 'User '.$id;
});
@nicolaskempf57
nicolaskempf57 / basic1.php
Created February 3, 2021 18:12
Laravel basics 1 : l'utilisateur connecte est accessible depuis la requête
<?php
namespace App\Actions\Account;
use App\Models\User;
class ShowDashboard
{
public function __invoke(Request $request, Client $client = null): Response
{
/** @var $user User * */
<?php
Route::put('post/{id}', function ($id) {})->middleware('role:editor');
@nicolaskempf57
nicolaskempf57 / middlewareGroups.php
Created May 8, 2020 13:24
Extract from Laravel App\Http\Kernel for my blog post on Laravel Middleware https://medium.com/blog-justenico/laravel-les-middlewares-59b651d80b10
<?php
/**
 * The application's route middleware groups.
 *
 * @var array
 */
protected $middlewareGroups = [
'web' => [
  \App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,