Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Missing argument 1 in get()

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?

like image 644
scottbear Avatar asked Feb 07 '23 18:02

scottbear


1 Answers

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().

like image 164
Muhammad Sumon Molla Selim Avatar answered Feb 10 '23 07:02

Muhammad Sumon Molla Selim