Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

raygun's avatar

I am confused about laravel site development

It seems I am going about site development using laravel. because looking for information on things is so hard. things like 3 way pivot tables. How are people developing. For instance, I want to build a site with a nav that has

    Home   News

at least for right now. Now I have assumed that I would need to have a controller and model for each. But everything I have seen is one dimensional with examples that don't really explain how its done with a site that has multiple nav links. Or maybe I'm going about this wrong, as I have said. I wanted to have a site search but it doesn't work well when returning the results. It only seems to work well if everything is from the same table. i only see examples on things that have to to be figured out after searching the net for hours. If I have posts and video are they to go in the same table where I have a column called "video" that has yes or no and I filter my searches based on that? Where can I go and see some real tutorials on how to make a site. a site with multi nav links? And for someone responds with "well Laravel isn't really used for that" I have this question, why are tutorials made showing how to use Laravel to make a website? I just want to develop and not have to ask any more questions about things, That I feel, that should have been answered already. Like a full site search.

0 likes
11 replies
Kryptonit3's avatar

@raygun while this site goes quite a bit in depth on the back-end aspect of PHP/Laravel (and is making a way to the front-end with a few video collections like vue.js etc), most people come to this site with at least a basic understanding of front-end html.

I just recently open sourced the entire code to make my site LaraBin.com - It is written in Laravel 5.1, you are more than welcome to look through it and see how I was able to build it.

With that being said, there is no "1" way to do things. There are multiple. Your question is quite vague. If you were to create a thread with specific issues, and questions in mind then it would go a lot further in producing fruitful answers.

opheliadesign's avatar

I think you're not quite understanding controllers and models. You do not need to have a controller for every link in your navigation and a model is specific to a set of data - for example, users, posts, images, etc.

So, for example, your News page might use the NewsController which in turn displays Post models - data from your posts table.

Something like:

class NewsController extends Controller {
     public function index()
     {
           $posts = App\Post::orderBy('created_at')->paginate(10);
          
          return view('news.index')->with('posts', $posts);
     }
}

As others have said, perhaps elaborate about what exactly you're struggling with? What have you tried?

raygun's avatar

@opheliadesign and @Kryptonit3 I want to return data from to different models when the page loads and when I do a search. But when I try this

public function index(Request $request)
    {

        $query = $request->get('q');
        $posts = $query
            ? Post::search('%'.$query.'%', ['title', 'subtitle', 'content_raw', 'tags.title'])->paginate(15)
            : Post::orderBy('published_at', 'desc')->paginate(15);



        $query = $request->get('q');
        $videos = $query
            ? Video::search('%'.$query.'%', ['title', 'subtitle', 'content_raw', 'tags.title'])->paginate(15)
            : Video::orderBy('published_at', 'desc')->paginate(15);


        $tag = $request->get('tag');
        $data = $this->dispatch(new BlogIndexData($tag));
        $layout = $tag ? Tag::layout($tag) : 'blog.layouts.index';



        return view($layout, $data)->withPosts($posts)->withVideos($videos);
    }

I get this error

Call to undefined method Illuminate\Database\Query\Builder::search()

but if I do this

    public function index(Request $request)
    {

        $query = $request->get('q');
        $posts = $query
            ? Post::search('%'.$query.'%', ['title', 'subtitle', 'content_raw', 'tags.title'])->paginate(15)
            : Post::orderBy('published_at', 'desc')->paginate(15);


        $tag = $request->get('tag');
        $data = $this->dispatch(new BlogIndexData($tag));
        $layout = $tag ? Tag::layout($tag) : 'blog.layouts.index';



        return view($layout, $data)->withPosts($posts);
    }

it works and I'm using "search". so I don't get it

raygun's avatar

but @Kryptonit3

but if I do this

    public function index(Request $request)
    {

        $query = $request->get('q');
        $posts = $query
            ? Post::search('%'.$query.'%', ['title', 'subtitle', 'content_raw', 'tags.title'])->paginate(15)
            : Post::orderBy('published_at', 'desc')->paginate(15);


        $tag = $request->get('tag');
        $data = $this->dispatch(new BlogIndexData($tag));
        $layout = $tag ? Tag::layout($tag) : 'blog.layouts.index';



        return view($layout, $data)->withPosts($posts);
    }

it works and I'm using "search". so I don't get it

Kryptonit3's avatar

what is the line number the error is referring to? The only common denominator is that Post works. Chances are your Video model doesn't have the use SearchableTrait; on it.

raygun's avatar

@Kryptonit3 this is the error and line number

BadMethodCallException in Builder.php line 1994:
Call to undefined method Illuminate\Database\Query\Builder::search()

and this is what I'm using in my Post.php model

use App\Services\Markdowner;
use Illuminate\Database\Eloquent\Model;
use Carbon\Carbon;
use Sofa\Eloquence\Eloquence;
raygun's avatar

I figured it out I had to put "use Eloquence;" in my Video model

Please or to participate in this conversation.