Reputation: 155
I am trying to get all records from a table named 'producers', but I get the following error.
Missing argument 1 for Illuminate\Support\Collection::get(), called in /var/www/html/wines/storage/framework/views/ac350063efb624ac50d199628897fd7d72bc196c.php on line 63 and defined (View: /var/www/html/wines/resources/views/admin/producers.blade.php)
Here are my files: (migration)
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateProducerTable extends Migration {
public function up()
{
Schema::create('producers', function (Blueprint $table) {
$table->increments('id');
$table->string('producer_name');
$table->string('phone_number');
$table->string('user_id')->unique();
$table->string('avatar')->default('default.jpg');
$table->timestamps();
});
}
public function down()
{
Schema::drop('producers');
}
}
My ProducerController
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
class ProducerController extends Controller {
public function __construct() {
$this->middleware('isProducer');
} }
The producer model:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Producer extends Model {
protected $table = 'producers';
protected $fillable = [
'id','producer_name', 'phone_number','user_id','avatar'
];
protected $hidden = [
];
}
Then when I use
public function admin_producers() {
return view('admin.producers',array('user'=>Auth::user(),'producer'=>Producer::get()));
}
on the controller to get all my records I get that error. I have also tried with Producer::all() but with the same result, no luck. I am doing something stupid here?
Upvotes: 4
Views: 10180
Reputation: 4089
The Eloquent all()
method will return all of the results in the model's table. Use get()
only, when you need to add constraints to queries.
So, use all()
instead of get()
.
Upvotes: 7