title: laravel display data on a page based on id
body: <p>I have a page that shows links with name of businesses that are retrieved in database like this:</p>
  
  <p>Controller:</p>
  
  <pre><code>public function viewBusiness() {
  // Return our "website" object
  $business = Business::all();
  // Pass the contents of the "html" property to the view
  return view('viewBusiness', ['business' =&gt; $business]);
  }
  </code></pre>
  
  <p>View:</p>
  
  <pre><code>@extends('master') @section('title', 'Live Oldham') @section('content')
  @section('content')
              @foreach ($business as $businesses)
          &lt;a target="_blank" href="{{ url('business/' . $businesses-&gt;name) }}"&gt; {{($businesses-&gt;name) }}
          &lt;/a&gt; @endforeach       
  @endsection
  </code></pre>
  
  <p>Route:</p>
  
  <pre><code>Route::get('business/list', 'BusinessController@viewBusiness')-&gt;name('viewBusiness');
  </code></pre>
  
  <p>I then have added a function where user click on a link and it is taken to a page which displays all data for that specific business, however it diplays all data but for all businesses.</p>
  
  <p>Controller:</p>
  
  <pre><code>function displayBusiness() {
      $business = Business::all();
      $address = Address::all();
      return view('displayBusiness', ['business' =&gt; $business, 'address' =&gt; $address]);
  }
  </code></pre>
  
  <p>View:</p>
  
  <pre><code>@foreach ($business as $businesses)
      &lt;p&gt;{{$businesses-&gt;name}}&lt;/p&gt;
      &lt;p&gt;{{$businesses-&gt;email}}&lt;/p&gt;
  @endforeach
  @foreach ($address as $addresses)
      &lt;p&gt;{{$addresses-&gt;firstline_address}}&lt;/p&gt;
      &lt;p&gt;{{$addresses-&gt;secondline_address}}&lt;/p&gt;
      &lt;p&gt;{{$addresses-&gt;town}}&lt;/p&gt;
      &lt;p&gt;{{$addresses-&gt;city}}&lt;/p&gt;
      &lt;p&gt;{{$addresses-&gt;postcode}}&lt;/p&gt;
      &lt;p&gt;{{$addresses-&gt;telephone}}&lt;/p&gt;
  @endforeach
  </code></pre>
  
  <p>Route:</p>
  
  <pre><code>Route::get('business/{name}', 'BusinessController@displayBusiness')-&gt;name('displayBusiness');
  </code></pre>
  
  <p>Now here's the question, how can this code be modified so only a business that match either bussiness->name or business->id is displayed. (I guess name is taken when user clicks on a name.</p>
  
  <p>Another question is how to restrict the url so that if localhost/business/{name} is not equal to any business->name in the database returns error? at the moment it shows the page no matter what you enter.</p>
  
  <p>Thanks!</p>