Laravel | Cookbook
Inhaltsverzeichnis
Tutorials, Links
- https://kinsta.com/blog/laravel-tutorial/#6-best-free-laravel-tutorial-sites
- https://laravel-news.com/
- https://laravel-news.com/learning-laravel-in-2021
- https://laravel.com/docs/8.x
- https://www.tutsmake.com/category/laravel-tutorial/
- https://www.tutsmake.com/laravel-interview-questions-answers-for-1235-year-experience/
- https://www.larashout.com/
- https://learn2torials.com/category/laravel
- https://eloquentbyexample.com/
- https://laravel.com/docs/8.x/eloquent#introduction
Erste Schritte
Erstellen einer ersten Anwendung
laravel new app --jet cd app
Datenbankkonfiguraton anpassen in der Datei .env
DB_HOST=
Datenbank erstellen
composer update php artisan key:generate php artisan migrate
Livewire Komponenten hinzufügen
php artisan vendor:publish --tag=jetstream-views
Frontend erstellen
npm install npm run dev php artisan serve
Upgrade Composer
composer self-update --2
Datenbanken
https://laravelarticle.com/laravel-ajax-datatable-crud
Controller
Visitor Count
https://postsrc.com/posts/how-to-implement-visitor-views-or-visitor-counter-in-laravel-application
Links
- https://laravel-news.com/
- https://laravel-news.com/learning-laravel-in-2021
- https://laravel.com/docs/8.x
- https://www.tutsmake.com/category/laravel-tutorial/
- https://www.tutsmake.com/laravel-interview-questions-answers-for-1235-year-experience/
- https://www.larashout.com/
- https://learn2torials.com/category/laravel
- https://eloquentbyexample.com/
- https://laravel.com/docs/8.x/eloquent#introduction
Routing
Alle Routen anzeigen
php artisan route:list
Routen dynamisch erzeugen
composer require illuminate/support
use Illuminate\Support\Facades\File;
function generateRoutes($basePath, $baseNamespace = 'Pages', $routePrefix = '/')
{
    $files = File::allFiles($basePath);
    foreach ($files as $file) {
        $relativePath = str_replace([$basePath, '.vue'], '', $file->getRelativePathname());
        $routeName = str_replace(DIRECTORY_SEPARATOR, '.', $relativePath);
        $routeUri = str_replace(DIRECTORY_SEPARATOR, '/', $relativePath);
        // Example: if file is `resources/js/Pages/Examples/layout-discord.vue`
        // $routeName = 'Examples.layout-discord';
        // $routeUri = 'examples/layout-discord'
        Route::get($routePrefix . $routeUri, function () use ($relativePath, $baseNamespace) {
            return Inertia::render($baseNamespace . str_replace('/', '\\', $relativePath));
        })->name($routeName);
    }
}
generateRoutes(resource_path('js/Pages'));Mail / SMTP
Lokaler Mailserver für SMTP Testing
MailHog: Web and API based SMTP testing
UI
Versionen anzeigen
In dem entsprechenden Blade-View:
<p class="mb-2">
    Laravel Version: <span class="font-mono">{{ $page.props.laravelVersion }}</span><br>
    PHP Version: <span class="font-mono">{{ $page.props.phpVersion }}</span>
</p></p>Option A — Routing anpasssen
routes/web.php
use Illuminate\Foundation\Application;
use Illuminate\Support\Facades\Route;
use Inertia\Inertia;
Route::get('/', function () {
    return Inertia::render('Welcome', [
        'laravelVersion' => Application::VERSION, // or app()->version()
        'phpVersion'     => PHP_VERSION,
    ]);
});
Option B — Global jeder Seite übergeben
app/Http/Middleware/HandleInertiaRequests.php
use Illuminate\Foundation\Application;
use Inertia\Middleware;
use Illuminate\Http\Request;
class HandleInertiaRequests extends Middleware
{
    // ...
    public function share(Request $request): array
    {
        return array_merge(parent::share($request), [
             ... vorherige Rückgabewerte beibehalten
            'laravelVersion' => Application::VERSION, // or app()->version()
            'phpVersion'     => PHP_VERSION,
        ]);
    }
}
Leave a Reply