2

Having a problem with the links in the menus.

At the moment, the linkage between the views is done through links inside of views which are ruled by the controller.

Example, in this view,

here

we have the show view for companies.

The link that says 'Edit About Page Tiago', looks like the following:

<p><a href="{{route('company.companies.about.edit', $company->companyID)}}">Edit About Page {{$company->Company_Name}}</a></p>

where $company->companyID is being grabbend from the controller, which looks like this:

public function show($id)
    {
        //

        $company = Company::findOrFail($id);

        return view('company.companies.show', compact('company'));

    }

and has the following route:

GET|HEAD  | company/companies/{company} | company.companies.show | App\Http\Controllers\CompanyCompaniesController@show | web,company   

GET|HEAD  | company/companies/about/{about}/edit | company.companies.about.edit | App\Http\Controllers\CompanyAboutController@edit | web,company   |

At the moment, when I try to access, through the menu, 'About', I'm trying to access this:

        <li>
            <a href="{{route('company.companies.about.edit', $company->companyID)}}"><i class="fa fa-dashboard fa-fw"></i> About</a>
        </li>

which is code inside of a layout view. The following error comes through:

here

What can I do for, once pressing the 'About', to be redirected in the same way like in the 'Edit About Page Tiago'?

Asking it in another way, where can I give the information to $company if that variable is inside of a layout view and not in a normal view which I can do through the controller?

It might be a basic problem to solve, but somehow is blocking me.

Any given help is appreciated

Tiago

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Tiago Martins Peres
  • 14,289
  • 18
  • 86
  • 145
  • 1
    Try to dump the company variable in the controller (var_dump($name_of_variable)) – Imam Assidiqqi Nov 22 '16 at 22:59
  • 1
    What do you mean? To which controller? Because is a layout view. How is that done for this specific case? – Tiago Martins Peres Nov 22 '16 at 23:01
  • 3
    You can refer to [Data With All Views](https://laravel.com/docs/5.3/views#passing-data-to-views) in the **Sharing Data With All Views** section ! hope that helps – Maraboc Nov 22 '16 at 23:11
  • it gives some orientation, let's see what one can do with that, thanks! – Tiago Martins Peres Nov 22 '16 at 23:24
  • 1
    Please do *not* add `[solved]` to post titles. Questions do not need to be marked as such. If you have found your own solution, feel free to post that as an answer below, or if one of the answers was helpful in solving the problem for you, consider marking that answer as accepted. Otherwise, there is nothing you need to do. Remember that questions and answers are here for *future visitors*, and they'll make their own determination on what is helpful, or if they have found a solution, wether or not they'll post a new answer then. – Martijn Pieters Feb 07 '17 at 07:47

2 Answers2

2

As @Maraboc said, you can share data with all your views in a service provider, but in order to do this you need to know/set the values ahead of time, during the bootstrapping process. This functionality is typically used for global values like base titles, meta tags, etc that you want to manage say in your database or through some sort of custom CMS.

There is another way to share variables across views using View Composers which may better fit your use case.

samrap
  • 5,595
  • 5
  • 31
  • 56
0

I was having the same issue. I was using different method than default route.In my view,

<a href="editcompany?id={{$company->companyID}}" class="btn btn-xs btn-info" >EDIT </a>

in my route.php I have

Route::get('editcompany','CompanyController@edit');

In my Controller, edit function looks like this

public function edit()
{

    $id = Input::get('id');
    $company = Company::find($id);
    return view ('your view',compact('company'));
}
Sachith Muhandiram
  • 2,819
  • 10
  • 45
  • 94
  • 2
    Found this link, which might have some great info. Trying to take some 'juice' out of it. http://stackoverflow.com/questions/28608527/how-to-pass-data-to-all-views-in-laravel-5 At the moment, though about: 1- create a provider with artisan 2- use the company info in the boot() method. Why this wouldn't work: we would be trying to fetch database records before they exist (lorey Oct 4 '15 at 21:41) (it has 6 upvotes) – Tiago Martins Peres Nov 22 '16 at 23:31