PROGRAMMING     CLIMBING

  minte9
reminder




Last update:   18-01-2022

Laravel

Version: Lavavel v8.5 Basics: Route, Controller, View
 
cd /var/www/tests.local/php/laravel/

composer create-project laravel/laravel myproject
 
sudo chown -R $USER:www-data storage
 
http://tests.local/php/laravel/myproject/public/
    # Welcome page Laravel
Add user route And user controller and view
 
// routes/web.php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\UserController;

Route::get('/', function () {
    return view('welcome');
});

Route::get('/user/{id}', // Look Here
    [UserController::class, 'show']
);
 
// App\Http\Controllers\UserController.php

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use App\Models\User;

class UserController extends Controller
{
    public function show($id)
    {
        return view('user', ['id' => $id]);
    }
}
 
// resources/view/user.php

Hello user <?= $id ?>
It works!
 
http://tests.local/php/laravel/myproject/public/user/10
    # Hello user 10

Questions    
Laminas v3
        A B C D E F
🔔
1/1