I have this code in routes:
Route::get('forum/{fname}/{fid}', 'viewForum@showForum');
in controller:
<?php
namespace App\Http\Controllers;
use DB;
use View;
class viewForum extends Controller
{
public function showForum($fname, $fid)
{
return View::make('forum', [
'forums' => DB::table('forums')
->where('id', $fid)
->where('seo-name', $fname)
->select()
->get()
]);
}
}
And in the layout:
@extends('layouts.main')
@section('content')
@foreach($forums as $forum)
{{ $forum->name }}
@endforeach
@stop
It's ok, but when I write bad {fname} or {fid} then nothing prints, white page, but i wan't to show error, how can I do it? I've created same with viewProfile :
<?php
namespace App\Http\Controllers;
use DB;
use View;
class viewProfile extends Controller
{
public function showProfile($uname, $uid)
{
$u = DB::table('users')
->where('id', $uid)
->where('name', $uname)
->first();
return View::make('users', [
'username' => $u->name,
'userid' => $u->id,
'email' => $u->email,
'regdate' => $u->created_at
]);
}
}
In this code error prints, but in first nope, why? How can I fix it? Thanks in advance
I'm fixed, I just added this code:
@extends('layouts.main')
@section('content')
@forelse($forums as $forum)
{{ $forum->name }}
@empty
<div class="alert alert-danger">Forum not found</div>
@endforelse
@stop