Database / Laravel

Asked

Viewed 20 times

-2

good afternoon, I am trying to create a product in relation to your identified label, for example when sending the form a null line is created in the database.

public function store(Produto $produto, Request $request)
{

    $data = $this->requestValidate();


    $produto->user_id = Auth::user()->id;
    $produto->save();
    $produto->tags()->attach(request('tags'));

    if ($request->hasFile('image') && $request->image->isValid()) {
        $name = uniqid(date('HisYmd'));
        $extension = $request->file('image')->getClientOriginalExtension();
        $nameFile = "{$name}.{$extension}";
        $imagePath = $request->image->storeAs('img_produtos', $nameFile, 'img_produtos');
        $data['image'] = $imagePath;
    }



    Produto::create($data);
    return redirect(route('user.profile'));
}

here is how it appears in the database

inserir a descrição da imagem aqui

Can someone help me? I’m a beginner in Laravel.

1 answer

0

Your first code is

$produto->user_id = Auth::user()->id;
$produto->save();

is responsible, it will create a record in the database and enter only the user id.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.