Laravel job, missing parameter - laravel

I try to dispatch a job in Laravel.
Job:
public $items;
public $milestone_delivery_date;
public $project_id;
public function __construct($items, $milestone_delivery_date, $project_id)
{
$this->items = $items;
$this->milestone_delivery_date = $milestone_delivery_date;
$this->project_id = $project_id;
}
PartController:
public function storeImportedParts(Request $request, Project $project)
{
$milestones = $project->milestones->where('material_delivery', 1);
$milestone_delivery_date = '';
if ($milestones->count()) {
$milestone_delivery_date = $milestones->first()->due_date;
}
$items = $request->items;
$this->dispatch(new StoreImportedParts($items, $milestone_delivery_date, $project));
In this case, the following error occurs:
[2020-01-31 08:23:16] local.ERROR: Too few arguments to function App\Jobs\StoreImportedParts::__construct(), 0 passed in /xxx/xx/xxx/xxx/app/Jobs/StoreImportedParts.php on line 37 and exactly 3 expected
???
If I change the vars with numbers like this, it works:
$this->dispatch(new StoreImportedParts(1, 1,1));
Of course, there is an error but the params arrive in the Job:
[2020-01-31 08:24:02] local.ERROR: Invalid argument supplied for foreach() {"userId":2,"exception":"[object]
In PHPStorm, the display is also different:
Why the params do not pass into the Job?

Related

How to pass multiple parameters to route

Hello i have this function called show and it has 2 parameters id and options this is the code from blade.php :
<a href="{{route('orders.show',$order->id,'1')}}">
<button>Edit</button>
</a>
The number one is static but i have another button that has value 2 now this is the code from the controller:
public function show($id, $option)
{
$orders = Order::with('client', 'products')->where('id', $id)->firstOrFail();
$clientList = Client::all();
$productList = Product::all();
switch ($option)
{
case 1:
{
return view('orders.edit', compact('orders', 'clientList', 'productList'));
break;
}
case 2:
{
return view('orders.show', compact('orders', 'clientList', 'productList'));
break;
}
}
}
But when i execute teh code i get this error:
Too few arguments to function App\Http\Controllers\OrderController::show(), 1 passed in /home/user/Desktop/k_project/vendor/laravel/framework/src/Illuminate/Routing/Controller.php on line 54 and exactly 2 expected
Basically the second argument is not passing i used another method like this:
Student detail
From this page: Page
While before i passing just one value $id and it worked fine but now i need a second parameter to pass.
This is my route definition that just one value passing $id works but with two values passing $id and $option will make error:
Route::resource('orders', OrderController::class);
Your route has 3 parameters id, parameter, name.
You can have two solutions for that.
1. First Solution
route.php
Route::get('/orders/show/{id}', 'OrderController#show')->name('orders.show');
OrderController.php
public function show(Request $request, $id)
{
$name = $request->input('name');
$parameter = $request->input('parameter');
....
}
2. Second Solution
route.php
Route::get('/orders/show/{id}/{name}/{parameter}', 'OrderController#show')->name('orders.show');
OrderController.php
public function show($id, $name, $parameter)
{
....
}

Where can I put paginate()?

I am trying put paginate(10) to add a pagination later, but when I added it it gives me this error:
Undefined property: Illuminate\Pagination\LengthAwarePaginator::$product
Here is my controller where I want add the pagination(10):
public function index()
{
$user_id = auth()->user()->id;
$user = User::find($user_id);
return view('your')->with('product', $user->product);
}
I did try this:
public function index()
{
$user_id = auth()->user()->id;
$user = User::find($user_id)->paginate(10);
return view('your')->with('product', $user->product);
}
How can I avoid the undefined property error?
Actually find function is used for getting only 1 result and you are applying pagination on that which is resulting into an error.
You might be wanting the products data to be paginated, For that do like this
public function index()
{
$user_id = auth()->user()->id;
$user = User::find($user_id)->product()->paginate(10);
return view('your')->with('product', $user);
}

Laravel: Trying to get property of non-object although return value is right

SOLVED
I get this error when I got to a page where I call a method in template.
ErrorException in Product.php line 104:
Trying to get property of non-object (View: C:\wamp64\www\ibpc\resources\views\admin\products\edit.blade.php)
In blade template I am calling a method attribute:
{{ $product->attribute($attribute->id) }}
$product in template is passed from controller as:
$product = Product::with('categories.specifications.attributes')->find($id);
Method attribute in Product.php:
public function attribute($id)
{
$attribute = $this->attributes()->find($id);
$test = $attribute->pivot->value;
return $test;
}
I did debug with xdebug and everything seems to be fine:
Why the error?
If I do something like this then I get no errors:
public function attribute($id)
{
return 'Hello';
}
I had to check for empty values...
public function attribute($id)
{
$attribute = $this->attributes()->find($id);
if ($attribute) {
$test = $attribute->pivot->value;
} else {
$test = null;
}
return $test;
}

Missing argument 1 for Teepluss\Theme\Theme::Teepluss\Theme\{closure}()

i am using a theme manager for la-ravel Teepluss but when i bind any things it gives this error :
Missing argument 1 for Teepluss\Theme\Theme::Teepluss\Theme{closure}()
here is the screenshot of error
http://i.imgur.com/elQ5qLY.png
just adding this line $this->theme->bind('active', 'home'); to the below code gives error
public function showWelcome()
{
$this->theme->layout('default');
$this->theme->setTitle($this->config['SEO']['home']['title']);
$this->theme->setMeta_desc($this->config['SEO']['home']['meta_description']);
$this->theme->setMeta_keywords($this->config['SEO']['home']['meta_keywords']);
$this->theme->bind('active', 'home');
return $this->theme->scope('home.index')->render();
}
i think the package theme binding has some issues
Finally i found the issue. There is bug in this package. There shouldn't be any argument in the clouser and the code should be something like this :
public function bind($variable, $callback = null)
{
$name = 'bind.'.$variable;
// If callback pass, so put in a queue.
if ( ! empty($callback))
{
// Preparing callback in to queues.
$this->events->listen($name, function() use ($callback, $variable)
{
return ($callback instanceof Closure) ? $callback() : $callback;
});
}
// Passing variable to closure.
$_events =& $this->events;
$_bindings =& $this->bindings;
// Buffer processes to save request.
return array_get($this->bindings, $name, function() use (&$_events, &$_bindings, $name)
{
$response = current($_events->fire($name));
array_set($_bindings, $name, $response);
return $response;
});
}

Error while pushing values to blade template in laravel 4

My code is
public function listCompanies()
{
$companyObj = new company();
$companies = $companyObj->getCompanies();
$this->layout->content = View::make('admin/main',['companies'=>$companies]);
}
The error I am getting is
ErrorException
Creating default object from empty value
The error line is
$this->layout->content = View::make('admin/main',['companies'=>$companies]);
Set a:
protected $layout = 'your_layout_name';

Resources