0

I have installed Voyager for Laravel. I cannot understand the relation and why it gives me a dropdown menu each time.

Here is what I have done:

Image showing relations

As you can see I have created a relation "Coupon" "belongsTo" "users"

In the coupon table I have created a user_id column.

All I want is the user id to be showing in the next page so I can save it to the DB when the user creates the coupon. The problem is that when I log as a user and create a coupon, I see a dropdown menu rather than the id of the user:

Image showing user panel

Any idea why please?

Thank you.

Benny
  • 430
  • 6
  • 17

1 Answers1

2

Assuming "Coupon" as model for your table, then you can change the save function to fill the default value of "belongsTo" with the user id which is current authenticated like this :

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Coupon extends Model
{
    public function save(array $options = [])
    {
        if(!isset($this->belongsTo)){
            $this->belongsTo = \Auth::user()->id;
        }
        parent::save();
    }
}

i hope this will solve your issue.

And answer to your actual question, there is no Next page available in Voyager Bread, and relationship in voyager will always create a dropdown list as clearly mentioned in there documentation https://docs.laravelvoyager.com/core-concepts/bread-builder#relationships

Abhinav Verma
  • 425
  • 7
  • 14
  • Thanks, I ended up giving up on Voyager, too many issues. They only help people for Voyager issues and not Laravel, the problem is that beginners have no idea which is which, they need to create a website where there is more info covering issues that people may have while using Voyager(Laravel included) or people will just give up as you download it to apparently build a project faster but you end up spending so much time looking for answers to basic problems that time gets wasted. – Benny Mar 13 '19 at 12:06
  • Benny i have been using Voyager, since last almost 2 years and i am never disappointed by its feature, if you are looking for "BREAD", i suggest go with Voyager they have really nice admin panel, rest is your call, we have almost build 3 custom projects based on Voyager. and all of them working flawlessly. – Abhinav Verma Mar 13 '19 at 12:09
  • 1
    The problem with Voyager is that basic features like "User should only see his own records" are not there, you end up copying their controllers into your own and get things messed up when there is an update as some of the functions stop working which happened to me when I updated Voyager. So I started to code my own vue and laravel api admin panel solution as it is too difficult to work my way through voyager when you need more complex features to work. – Benny Mar 14 '19 at 13:11
  • Agreed ! when you update voyager you may get stuck, due to changes etc, but that's common in any opensource being update or so. – Abhinav Verma Mar 14 '19 at 13:14
  • Thanks for the talk, no worry, I moved away from Voyager now. Enjoying vue and just the Laravel API on its own. – Benny Mar 15 '19 at 14:09
  • Same here nice talking, happy coding – Abhinav Verma Mar 15 '19 at 14:10