Customization

Customize Prezet's Controllers

Prezet provides default controllers that handle the core functionality of the blogging engine. However, you may want to customize these controllers to add your own logic or modify the existing behavior.

#Default Controllers

Prezet uses the following controllers:

  • IndexController: Handles the index page that lists all articles.
  • ShowController: Displays individual articles.
  • ImageController: Manages image serving and optimization.
  • OgimageController: Handles Open Graph images for social media sharing.

These controllers are located in the vendor/benbjurstrom/prezet/src/Http/Controllers directory.

#Overriding a Controller

To override a Prezet controller:

  1. Copy the controller you want to customize from the vendor directory to your app/Http/Controllers directory.
  2. Update the namespace at the top of the file to match your application's namespace.
  3. Modify the controller as needed.
  4. Finally, update the routes/prezet.php file to use your new controller.

Here's an example of overriding the IndexController:

  1. Copy vendor/benbjurstrom/prezet/src/Http/Controllers/IndexController.php to app/Http/Controllers/PrezetIndexController.php.

  2. Update the namespace in the new file:

1namespace App\Http\Controllers;
2 
3use BenBjurstrom\Prezet\Http\Controllers\IndexController as BaseIndexController;
4 
5class PrezetIndexController extends BaseIndexController
6{
7 // Your custom logic here
8}
  1. Update the routes/prezet.php file:
1use App\Http\Controllers\PrezetIndexController;
2 
3Route::get('prezet', PrezetIndexController::class)
4 ->name('prezet.index');

#Customizing Controller Logic

Once you've overridden a controller, you can customize its logic. For example, you might want to add additional data to the view in the IndexController:

1public function __invoke(Request $request)
2{
3 $articles = $this->getArticles();
4 $featuredArticle = $this->getFeaturedArticle();
5 
6 return view('prezet::index', [
7 'articles' => $articles,
8 'featuredArticle' => $featuredArticle,
9 ]);
10}
11 
12private function getFeaturedArticle()
13{
14 // Your logic to get a featured article
15}

Note: If you're only changing how things are displayed, consider customizing the Blade views instead. See the article on customizing Blade templates for more information.