mardi 15 septembre 2020

Laravel - How to execute store resource?

I'm creating a CRUD app. But when I code in method store I have a problem: I'm trying to create a variable $contact = new Contact(). It's message: Undefined type 'App\Contact'.

This ContactController.php

    use App\Contact;
    ....
    public function store(Request $request)
    {
        $request->validate([
            'first_name'=>'required',
            'last_name'=>'required',
            'email'=>'required'
        ]);
        $contact = new Contact([
            'first_name' => $request->get('first_name'),
            'last_name' => $request->get('last_name'),
            'email' => $request->get('email'),
            'job_title' => $request->get('job_title'),
            'city' => $request->get('city'),
            'country' => $request->get('country')
        ]);
        $contact->save();
        return redirect('/contacts')->with('success', 'Contact saved!');

    }

I made it with this link: https://medium.com/techiediaries-com/laravel-7-crud-tutorial-build-a-crud-app-with-mysql-and-bootstrap-4-4ed8e94f2db0



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire