Support the ongoing development of Laravel.io →
posted 6 years ago
Eloquent
Last updated 2 years ago.
0

In your model you can just add the protected $fillable property needed in case you need to mass assign values.


    <?php

    namespace App;

    class Cat extends Model {

        protected $fillable = ['name', 'color', 'lives'];

    }

This means that if you want to send the Request from you views to you controller:


    <?php

    namespace App\Http\Controllers;

    class CatController extends Controller {

        public function store(Request $request) {

            $cat = new Cat();

            $cat->name = $request->input('name');
            $cat->color = $request->input('color');
            $cat->lives = $request->input('lives');

            $cat->save();

            return redirect()->route('cats.index')
                     ->with('message', 'The cat ' . $cat->name . ' has been created successfully');

        }

    }

So aswering your question, the attributes of the Cat should be in the protected $fillable property.

Good Luck bro!

0

Thanks for an excellent answer. However fillable would never be a complete list as its only database fields that I want to be editable by request right? so if I could have a property that is legitimately not in that list. And the fillable list does not even hint at what type it should be.

Looking for something more concrete but I don't think its there.

0

Thanks and yes you're right, I guess you can always declare the properties in you model. Good Luck Ste.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.