I am using this code inside my PHP
file:
university.blade.php
{{ url( $universities->universityName.'/students') }}" >
The problem is that displays just http://localhost:8000/students
, not the value of variable. So what is the solution?
Probably $universities->universityName
is empty
Lets assume your controller looks like this:
<?php namespace App\Http\Controllers
use App\University; // I assume this is your model
class 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With