5

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?

3
  • Can i see your blade code? Commented Nov 12, 2015 at 7:16
  • 1
    Probably $universities->universityName is empty, kindly include the controller that presents university.blade.php Also try {!! url( $universities->universityName.'/students') !!} Commented Nov 12, 2015 at 7:16
  • NOTE: {{}} is for vers laravel 4 while {!! !!} is for the newest version Commented Nov 12, 2015 at 7:22

2 Answers 2

3

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
Sign up to request clarification or add additional context in comments.

1 Comment

Try {!! url("{$univerisity->university Name}/students") !!}
2

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

1 Comment

It should be as simple as {{$yourfirstvariable.$id.$yourvariable}}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.