Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

Lakshan-Madushanka/movieshark

6 stars
2 code files
View Lakshan-Madushanka/movieshark on GitHub

app/Http/Requests/Movie/MovieListStoreRequest.php

Open in GitHub
use App\Http\Payloads\WatchListPayload;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Auth;
 
class MovieListStoreRequest extends FormRequest
{
public function authorize(): bool
{
return Auth::check();
}
 
public function rules(): array
{
return [
'imdb_id' => ['string', 'nullable'],
'yts_id' => ['integer', 'nullable'],
'image' => ['string', 'nullable'],
'name' => ['string', 'required'],
'genres' => ['array', 'nullable'],
'my_rating' => ['integer', 'nullable', 'between:0,100'],
'released_date' => ['string', 'nullable'],
'downloaded_status' => ['date', 'nullable'],
'watched_status' => ['date', 'nullable'],
'description' => ['string', 'nullable'],
];
}
 
public function payload(): WatchListPayload
{
return new WatchListPayload(
name: $this->validated('name'),
imdb_id: $this->validated('imdb_id'),
yts_id: (int) $this->validated('yts_id'),
image: $this->validated('image'),
genres: $this->validated('genres'),
my_rating: (int) $this->validated('my_rating'),
released_date: $this->validated('released_date'),
downloaded_status: $this->validated('downloaded_status'),
watched_status: $this->validated('watched_status'),
description: $this->validated('description'),
);
}
}

app/Http/Controllers/Front/WatchList/WatchListController.php

Open in GitHub
use App\Http\Controllers\Controller;
use App\Http\Requests\Movie\MovieListStoreRequest;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Http\RedirectResponse;
use Illuminate\Routing\Redirector;
use Illuminate\Support\Facades\Auth;
use Inertia\Inertia;
use Inertia\Response;
 
class WatchListController extends Controller
{
// ...
 
public function store(MovieListStoreRequest $request): Redirector|RedirectResponse|Application
{
$payload = $request->payload();
 
Auth::user()->watchList->movies()->create($payload->toArray());
 
return back();
}
 
// ...
 
public function update(string $movieId, MovieListStoreRequest $request): RedirectResponse
{
$movie = Auth::user()->movies()->where('movies.id', $movieId)->firstOrFail();
 
$movie->update($request->payload()->toArray());
 
return back();
}
 
// ...
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.