how to echo strings and variable in laravel 5.1 blade
Probably $universities->universityName
is empty
Lets assume your controller looks like this:
<?php namespace App\Http\Controllersuse App\University; // I assume this is your modelclass UniversityController extends Controller{ public function index() { $universities = Univeristy::all(); return view('universities', compact('universities')); }}
Then later in your universities.blade.php
<a href="{!! url("{$univerisity->universityName}/students") !!}">Students</a>
or you can check if $universities->universityName
is empty, if it doesn't print the URL means its empty.
@if(!$universities || !$universities->universityName) <a href="{!! url("{$univerisity->universityName}/students") !!}">Students</a>@endif
As it seems you're passing some parameter in the url.
I assume that you want to print those parameter in your view
Here i wrote an example route, controller with view for your understanding.
Step 1 : Write a route method
Route::get('get/{id}', 'publicController@get');
Step 2 : Write a function inside your controller
public function get($id) { return view('get')->with('id', $id); }
Now you're returning the parameter that you passed to the view
Step 3 : Show in your View
Inside your view you can simply echo it using
{{ $id }}
So If you have this in your url
http://localhost/yourproject/get/14
Then it will print 14
Hope this helps you