Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Nevermind23's avatar

Create anime list like MAL

I want to create animelists on my website like Myanimelist.

This will be function for "Add To List" button.

public function addtoanimenlist(Request $request)
{
    $anime = Anime::findOrFail($request->id);
    Animelist::create([
    'user' => $request->user->name,
    'id' => $anime->id,
    'name' => $anime->title,
    'watchedEpisodes' => null,
    'totalEpisodes' => $anime->episodes,
    'userRating' => null,
    'status' => 'Watching'
    ]);
}

Maybe there is better way, or already written code for me and am I doing everything ok at all ?

0 likes
5 replies
tisuchi's avatar

I believe you will get error because you are doing wrongly. Just you findOrFail() no need to use get().

You need to correct like this-

    $anime = Anime::findOrFail($request->id);

The create method seems ok.

2 likes
Nevermind23's avatar

What about relationships ? it's not needed in this case ?

tisuchi's avatar

@Nevermind23 Relationships is not required here. Its just a simply adding data into database. Thats should be ok.

@MaverickChan

It seems that its ok. I don't know whether he has changed it or not.

2 likes

Please or to participate in this conversation.