This is my personal website.
If you are adding an article that needs additional logic you can send the request to a separate controller, which then sends the response back, in this instance it is a view (Illuminate\View\View).
If an article requires a collection of objects that need to be gathered, instead of putting that logic in the ArticleController@show method (which will be called every time you load an article, even when it doesn't need it) it will allow it to go to a different controller (where the gathering can be done) and return a view.
- Create the separate controller and extend the ShowArticle abstract class:
class BooksController extends ShowArticle
{
public function __construct(GetBooks $getBooks)
{
$this->getBooks = $getBooks;
}
public function show(Article $article): View
{
return view('articles.show.books', compact('article'))
->with('books', $this->getBooks->get());
}
}
- Create the view and extend the articles.show blade template
@extends('articles.show')
- Append the additional content within the view
@section('additional-content')
{{ print_r($books) }}
@append
- Declare the separate controller within the separate-controllers array in file config/articles.php. Where the key is the article id (primary key) and the value is the controller path.
return [
'separate-controllers' => [
4 => BooksController::class
]
];
- Docker
In your terminal run commands:
docker-compose up --build -d
docker exec --tty portfolio-v1_php_1 php artisan key:generate
docker exec --tty portfolio-v1_php_1 composer update
docker exec --tty portfolio-v1_php_1 php artisan migrate
docker exec --tty portfolio-v1_php_1 vendor/bin/phpunit tests