In my app , when i create a new post in the form we have two input file to upload 2 images, they goes to a public folder call "rutas" after create the post, i can see the images in that folder, but the path saved in the db is
/private/var/folders/38/dctw6dxj5d35c91z8hzz6csw0000gn/T/php9N8FnJ
why that happens ? how to solve it
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Ruta extends Model
{
use HasFactory;
protected $guarded = ['id', 'created_at', 'updated_at'];
public function getRouteKeyName()
{
return 'slug';
}
}
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Gate;
class StoreRutaRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return Gate::allows('ruta_access');
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, mixed>
*/
public function rules()
{
return [
'legNumber' => 'required',
'name' => 'required',
'slug' => 'required|unique:rutas',
'imageDep' => 'required|image|mimes: jpeg,png,jpg,gif|max:2048',
'icaoDep' => 'required',
'icaoDepContent' => 'required',
'icaoDes' => 'required',
'icaoDesContent' => 'required',
'imageDes' => 'required|image|mimes: jpeg,png,jpg,gif|max:2048',
'descriptionLeg' => 'required',
'rutaIfr' => 'required',
'departures' => 'required',
'arrivals' => 'required',
'approachs' => 'required',
];
}
}
public function store(StoreRutaRequest $request)
{
if ($image =$request->file('imageDep')) {
$destPath = 'rutas/';
$profileImage = "des" . date('YmdHis') . "." . $image->getClientOriginalExtension();
$image->move($destPath, $profileImage);
$ruta['imageDep'] = $profileImage;
}
if ($image2 =$request->file('imageDes')) {
$destPath2 = 'rutas/';
$profileImage2 = "dep" . date('YmdHis') . "." . $image2->getClientOriginalExtension();
$image2->move($destPath2, $profileImage2);
$ruta['imageDes'] = $profileImage2;
}
$ruta = Ruta::create($request->validated());
return redirect()->route('admin.rutas.index')->with('info', 'La ruta ha sido creada con éxito');
}