Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

How can I use custom controller with laravel? #2866

rodurma started this conversation in General
Discussion options

Hi,

How can I use custom controller with laravel?

I tried this:

#[ApiResource(
    operations: [
        new Post(
            controller: CreateBookController::class
        )
    ]
)]
class Book extends Model
{
    protected $fillable = [
        'isbn',
        'title',
        'description',
        'author',
        'publication_date',
    ];
}

And in my controller:

class CreateBookController extends Controller
{
    /**
     * Handle the incoming request.
     */
    public function __invoke(Request $request)
    {
        dd($request->all());

        return response()->json([], 201);
    }
}

But without sucess.

You must be logged in to vote

Replies: 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant
Morty Proxy This is a proxified and sanitized view of the page, visit original site.