Something wrong with my application. When I try to in list i get exception Call to undefined method Illuminate\Database\Query\Builder::getRelationship() (View: C:\Work\shooting_calendar\vendor\tcg\voyager\resources\views\formfields\relationship.blade.php) (View: X:\xx\xx\vendor\tcg\voyager\resources\views\formfields\relationship.blade.php). And don't know why it doesn;t work. Does someone have the same proble?
I have the same problem.
I realised that changing the file /vendor/tcg/voyager/resources/views/formfields/relationship.blade.php to the previous version in the repository It goes well, basically you have to change the line 14:
$query = $model::getRelationship($relationshipData->{$options->column});
by
$query = $model::find($relationshipData->{$options->column});
I am new on voyager and laravel and I don't know what consequences involves that change so i don't want to make a pull request by now.
Maybe if you don't want to modify the code in the tcg/voyager vendor folder, you could temporarily edit your user model adding this to the App\User
class User extends \TCG\Voyager\Models\User
{
// ... More code here
protected static $relationships = [];
public static function getRelationship($id)
{
if (!isset(self::$relationships[$id])) {
self::$relationships[$id] = self::find($id);
}
return self::$relationships[$id];
}
// ... More code here
}
It works for me but i am only learning and not making anything in a production app, I hope it will be fixed soon in the master branch
@aruberutochan until the fix is merged (I still get the error on a fresh install I did today), you can also create a template under /resources/views/voyager/formfields/relationship.blade.php to override the template that comes with Voyager by default (in stead of changing files in de vendor directory).
I had the same issue, and my workaround is to use this trait below in the models with relationship:
<?php
namespace App\Traits;
trait HasVoyagerRelationship
{
public static function getRelationship($id)
{
return self::find($id);
}
}
hi guys, how to solve this problem?
I am still getting the error. Not sure if the correct fix was merged.
For now the temporary fix is to override the relationship.blade.php file.
Step 1 - Create a new blade file -
resources\views\vendor\voyager\formfields\relationship.blade.php
Step 2 - Copy content from -
tcg\voyager\resources\views\formfields\relationship.blade.php
Step 3 - Paste in the newly created blade file and replace line 14th by -
$query = $model::find($relationshipData->{$options->column});
The correct fix was merged. If you have custom models (not ones that ship with Voyager), you'll need to add the HasRelationships trait to any model you use Voyager's relationship builder with.
hii ,
i had installed voyager but when i go to click on product nav facing this error can anyone help with this

Looks like you have something like this in your custom controller:
$relationships = $this->getRelationships($dataType);
...
$query = $model::select('*')->with($relationships);
You can safely remove the first line and change to second to
$query = $model::select('*');
Yes
Yes, remove it as per my previous comment.
Yes, remove it as per my previous comment.
sorrry but i couldnt understand what i need to do exactly
$relationships = $this->getRelationships($dataType); <- remove this line completely
$query = $model::select('*')->with($relationships); <- change this line so it is $query = $model->select('*');
ErrorException (E_ERROR)
Too few arguments to function TCG\Voyager\Models\DataRow::sortByUrl(), 0 passed in C:\xampp\htdocs\mfscl_website\storage\framework\views\af0f59f74b7ead321b3661535f5bd10077a2c768.php on line 61 and exactly 2 expected (View: C:\xampp\htdocs\mfscl_website\resources\views\vendor\voyager\products\browse.blade.php)
Previous exceptions
Too few arguments to function TCG\Voyager\Models\DataRow::sortByUrl(), 0 passed in C:\xampp\htdocs\mfscl_website\storage\framework\views\af0f59f74b7ead321b3661535f5bd10077a2c768.php on line 61 and exactly 2 expected (0)
error has been arised
please can any one help me
I have no idea what you are posting here.
Please ask in our Slack group.
i had just posted code where this variable $relationships has used in so many places so definitely i will get error is there any other way to solve ? and ya thanks for putting your effort
In your controller, you have to do the same for all methods (remove the line, change the other).
sortByUrl was changed before.
I suggest you look at our "new" BaseController and see whats changed and adapt it.
Too few arguments to function TCG\Voyager\Models\DataRow::sortByUrl(), 0 passed in C:\xampp\htdocs\mfscl_website\storage\framework\views\af0f59f74b7ead321b3661535f5bd10077a2c768.php on line 61 and exactly 2 expected (View: C:\xampp\htdocs\mfscl_website\resources\views\vendor\voyager\products\browse.blade.php) ◀"
@emptynick please help me
I had changed according to dat but now getting this error
guys can anyone help me
Too few arguments to function TCG\Voyager\Models\DataRow::sortByUrl(), 0 passed in C:\xampp\htdocs\mfscl_website\storage\framework\views\af0f59f74b7ead321b3661535f5bd10077a2c768.php on line 61 and exactly 2 expected (View: C:\xampp\htdocs\mfscl_website\resources\views\vendor\voyager\products\browse.blade.php) ◀"
Most helpful comment
I had the same issue, and my workaround is to use this trait below in the models with relationship: