Backend Development
Laravel
Subjective
Sep 30, 2025
Explain Custom Blade components in Laravel with code examples.
Detailed Explanation
Custom Blade components provide reusable UI elements:
**Creating Component:**
php artisan make:component Alert
**Component Class (app/View/Components/Alert.php):**
class Alert extends Component {
public $type;
public $message;
public function __construct($type = "info", $message = "") {
$this->type = $type;
$this->message = $message;
}
public function render() {
return view("components.alert");
}
}
**Component Template (resources/views/components/alert.blade.php):**
{{ ucfirst($type) }}!
{{ $message ?? $slot }}
**Using Component:**
Something went wrong!
Discussion (0)
No comments yet. Be the first to share your thoughts!
Share Your Thoughts