I am creating a shop.
Situation : I am a logged user, and I would like to post an article I would like to sale. There is an image, name, description etc... for now everything is ok !
This is my shop database called boutiques in french :
I created a file upload for the image :
public function CreateArticleAction(Request $request) {
$requestData = $request->all();
$fileName = time().$request->file('img')->getClientOriginalName();
$path = $request->file('img')->storeAs('boutique-storage', $fileName);
$requestData["img"] = 'public/img/'.$path;
dd($requestData);
Boutique::create($requestData);
return redirect('boutique')->with('flash_message', 'Article Addedd!');
}
And a model :
class Boutique extends Model
{
protected $fillable = [
"iduser",
"idproduit",
"nom",
"description",
"prix",
"img",
"quantité",
];
use HasFactory;
}
As you can see I can get everything I put on my inputs but I don't know how to get my session id back to post it on the database with my article !
EXAMPLE :
Caroline (idsession : 1) posted this ..... : article's information
Thank you for your help !!
you have tried what is written on the doc
$id = Auth::user()->getId();
https://laravel.com/docs/9.x/authentication#retrieving-the-authenticated-user