Boa noite, professor
Ao tentar salvar a série inserindo uma imagem jpeg encontro o seguinte erro: Path cannot be empty.
Segue o código abaixo
SeriesController:
public function store(SeriesFormRequest $request)
{
$coverPath = $request->file('cover')->store('series_cover','public');
$request->coverPath = $coverPath;
$serie = $this->repository->add($request);
EventsSeriesCreated::dispatch(
$serie->nome,
$serie->id,
$request->seasonsQty,
$request->episodesPerSeason,
);
return to_route('series.index')
->with('mensagem.sucesso', "Série '{$serie->nome}' adicionada com sucesso");
}
Model:
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Series extends Model
{
use HasFactory;
protected $fillable = ['nome', 'cover'];
public function seasons()
{
return $this->hasMany(Season::class, 'series_id');
}
}
class EloquentSeriesRepository implements SeriesRepository:
class EloquentSeriesRepository implements SeriesRepository
{
public function add(SeriesFormRequest $request): Series
{
return $serie = DB::transaction(function() use ($request){
$serie = Series::create([
'nome'=> $request->nome,
'cover'=> $request->coverPath,
]);
$seasons = [];
for ($i=1; $i <= $request->seasonsQty; $i++) {
$seasons[] = [
'series_id' => $serie->id,
'number' => $i,
];
}
Season::insert($seasons);
$episodes = [];
foreach ($serie->seasons as $season) {
for ($j=1; $j <= $request->episodesPerSeason; $j++) {
$episodes[] = [
'season_id' => $season->id,
'number' => $j,
];
}
}
Episode::insert($episodes);
return $serie;
});
}
Erro na linha $request->coverPath = $coverPath; Verifiquei o model, o create e o EloquentSeriesRepository. Está tudo conforme foi posto na aula. Como resolver este erro ?