Ad

Laravel 5: Cannot Redeclare App\Subscription::$fillable

So i have this error when I do a post request in my Laravel 5 website:

Cannot redeclare App\Subscription::$fillable

This is my SubscriptionController.php file. The error is caused when I try to post to localhost/subscription, which calls the store method in which I try to create a Subscription class, but causes an error.

I already tried making a Subscription instance in another method but this causes the same problem.

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Subscription;
use App\Http\Requests;
use App\Http\Requests\StoreSubscriptionRequest;
use App\Http\Controllers\Controller;

class SubscriptionController extends Controller
{
    public function __construct()
    {
        //$this->middleware('auth');
    }

    public function index(Request $request)
    {
        return view('subscriptions.index');
    }

    public function store(StoreSubscriptionRequest $request)
    {
        $sub = new Subscription;
    }
}

And this my Subscription.php file.

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Subscription extends Model
{
     protected $fillable = ['name'];
     protected $fillable = ['surname'];
     protected $fillable = ['street'];
     protected $fillable = ['city'];
     protected $fillable = ['postal'];
     protected $fillable = ['participants'];
     protected $fillable = ['colors1'];
     protected $fillable = ['colors2'];
}

Any ideas?

Ad

Answer

With these instructions:

 protected $fillable = ['name'];
 protected $fillable = ['surname'];

you are declaring the same $fillable field multiple times, and each time you set it as an array of one element.

Instead you should declare one field as an array of many elements:

protected $fillable = ['name', 'surname', 'street', 'city', 'postal', 'participants', 'colors1', 'colors2'];
Ad
source: stackoverflow.com
Ad