Сделал сервис и сделал BaseController который делает extends из Controller далее в своем контроллере делаю тоже самое только из BaseController, но laravel его не видит
<?php
namespace App\Http\Controllers\Post;
use App\Http\Controllers\Controller;
use App\Sevice\Post\Service;
class BasesController extends Controller
{
public $service;
public function __construct(Service $service)
{
$this->service = $service;
}
}
<?php
namespace App\Http\Controllers;
use App\Http\Controllers\Post\BasesController;
use App\Http\Requests\Post\StoreRequest;
use App\Http\Requests\Post\UpdateRequest;
use App\Models\Category;
use App\Models\Tag;
use Illuminate\Http\Request;
use App\Models\Post;
class PostController extends BasesController
{
public function contr() {
$post = Post::all();
return view('post.index', compact('post'));
}
public function index() {
$post = Post::find(2);
dd($post->tags);
}
public function test() {
return "h!";
}
public function create() {
$category = Category::all();
$tags = Tag::all();
return view('post.create', compact('category', 'tags'));
}
public function store(StoreRequest $request) {
$data = $request->validated();
$this->service->store($data);
return redirect()->route('post.index');
}
public function show(Post $post) {
return view('post.show', compact('post'));
}
public function edit(Post $post) {
$category = Category::all();
$tags = Tag::all();
return view('post.edit', compact('post', 'category', 'tags'));
}
public function update(UpdateRequest $request, Post $post) {
$data = $request->validated();
$tags = $data['tags'];
unset($data['tags']);
$post->update($data);
$post = $post->fresh();
$post->tags()->sync($tags);
return redirect()->route('post.show', $post->id);
}
public function destroy(Post $post) {
$post->delete();
return redirect()->route('post.index');
}
}