Laravel use array of controller to echo something in view -


i'm new laravel , i'm stuck @ this. code gives me results table

$categories = new categories(); $categories = categories::all(); 

in view got foreach loop values table: categories. so:

@foreach($categories $categories)     <tr>         <td>{{$categories->category_id}}</td>         <td>{{ $categories->description }}</td> @endforeach 

my question is, there way print values seperate? can put anchor before them? have put in array? output must this:

1----<a href="gogsm.php">gsm</a> 2----<a href="gogps.php">gps</a> 

thanks lot!

$categories = new categories(); // line??? $categories = categories::all();    @foreach($categories $category)     <tr>         <td>{{$category->id}}</td>         <td> <a href="{{ yourfunctionthatgeneratesurl($category) }}"> {{ $category->name }} </a> </td>         // or suggested in comments         <td> <a href="{{ $category->urltocategory }}"> {{ $category->name }} </a> </td>         // or can use 1 of laravel's url helpers         <td> <a href="{{ route('category.show', ['id' => $category->id ]) }}"> {{ $category->name }} </a> </td>          <td>{{ $category->description }}</td> @endforeach 

more info helpers can find in [docs][1]

edit

if have categories

category1   id - 1 name - gsm  category2   id - 2 name - gps 

with code

@foreach($categories $category)     <tr>         <td>{{$category->id}}</td>         <td><a href="go{{$category->name}}.php">{{$category->name}}</a></td>     </tr> @endforeach 

you'll

<tr>     <td>1</td>     <td><a href="gogsm.php">gsm</a></td> </tr> <tr>     <td>2</td>     <td><a href="gogps.php">gps</a></td> </tr> 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -