1) Writing view content within the closure
you can write the view content within the closure itself using the response()
function to create a custom response directly in the route closure. Here’s how you can do it:
PHP
use Illuminate\Support\Facades\Route;
Route::get('/thank-you', function () {
$content = "
<!DOCTYPE html>
<html>
<head>
<title>Thank You</title>
</head>
<body>
<h1>Thank you for your message!</h1>
<p>We appreciate your feedback.</p>
<button onclick=\"window.location.href = '/';\">Go Back to Homepage</button>
</body>
</html>
";
return response($content, 200)
->header('Content-Type', 'text/html');
});
In this example, we’ve included the HTML content directly within the closure as a string and returned it as a response using the response()
function. We set the HTTP status code to 200 (OK) and specify the content type as ‘text/html’.
This approach can be useful for simple cases where you want to define the view content directly in the route closure, but for more complex views or when you want to follow a more organized approach, it’s often better to use separate Blade view files as shown in the previous response.
2) Useful Laravel CLI Commands
PHP
php artisan -version | php artisan -V | php artisan key:generate
PHP artisan serve | php artisan help | php artisan storage:link
php artisan down | php artisan up | php artisan list
php artisan optimize | php artisan optimize:clear | php artisan config:clear
php artisan cache:clear | composer dump-autoload | php artisan route:clear
php artisan view:clear
php artisan make:migration blog | php artisan migrate | php artisan migrate:rollback --step=1
php artisan make:model DailyMotivation -m |
php artisan make:model DailyMotivation -mcr *try fs also
Laravel Run Specific Migration
php artisan migrate --path=/database/migrations/2019_12_04_131405_create_payments_table.php
php artisan make:seeder AdminTableSeeder |
php artisan make:controller SuperAdmin/DailyMotivationalController --resource
php artisan make:middleware UsersMiddleware | php artisan queue:table
php artisan make:job SendEmailJob | php artisan make:event SendMail
php artisan make:listener SendMailFired --event="SendMail"
php artisan make:provider ClientsServiceProvider | php artisan make:rule OlympicYear
php artisan make:auth | php artisan queue:work --tries=3 OR --once --queue=JobQueueName
php artisan make:mail |
php artisan migrate --pretend * this will show query about to fired on migration
Laravel 9 New Commands
***********************
php artisan about | php artisan db:show (need doctrine/dbal package) | php artisan db:table users
php artisan stubs:publish
With Laravel 9, you can "php artisan docs yourquery"!
More Artisan commands : https://artisan.page/