0

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
0

1 Answer 1

1

if you want to show all errors, Set APP_ENV=local in you .env file. Allow recursive 777 permission to /vendor and /storage folder.

It should work.. also make sure that in '/config/databse.php' file 'fetch' => PDO::FETCH_ASSOC, or 'fetch' => PDO::FETCH_CLASS, is written.

You should also see that DB::table('forums') ->where('id', $fid) ->where('seo-name', $fname) ->select() ->get(); return a 2D array, and you are required a single dimension array. Once you be able to show errors you will find all errors easily. :)

Sign up to request clarification or add additional context in comments.

Comments

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.