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

janmoes's avatar

Laravel Nova-flexible-content

I was looking for a flexible content solution for a laravel project. For example, if i have a HomeController and i want to show two types of content on the page, first a gallery of images and a couple of posts. i would have done this:


public function index(){
    $images = Images::all();
    $posts = Posts::all();

    return view('home')->with(compact('images', 'posts'));
}

When i was looking for a solution i found out about nova, but didn't understand the docs very well. What i'm trying to accomplish is a restricted page, where i can add/edit/delete all the content for the homepage, so images, custom text fields, adding video urls etc. Is that possible?

0 likes
8 replies
janmoes's avatar

The crud page will be behind a login yes. But i'm not looking for a simple resource controller. What i'm trying to accomplish is that the user can edit for example the homepage like this: The user can choose what kind of data field he wants on his page (video, image, gallery, content). And that the user can also create repeating fields. If i use pure laravel and i want a gallery and a couple of posts on the homepage i need to include 2 models within my controller. I just want 1 admin page per front end page to add all kinds of custom content

ollie_123's avatar

Hey @janmoes

I'm not sure what experience you currently have with Laravel but this is quite easily achievable.

The link i suggested was to get you started, whilst it may be "simple", it would be the foundation of what you're looking to do.

You could filter what content you would like shown on that particular page in a query on a status basis. (i.e if the status = displayed).... see controller for more info...

In your controllers you could then add various queries as required to call data & pass it to the view. For instance if you had all of your posts in a table you could call this in the controller as such:-

//DashboardController

use App\Post; // This is your model

public function show() 
{
    $posts = Post::where('status', 'displayed')->get();

    return view('your_page_name', compact('posts'));
}

Then in your view you could do something like:-

<h5>These are our recent posts</h5>

<div class="row">
@foreach ($posts as post)
    <div class="col-md-12">
        <h5>{{$post->title}}</h5>
        <p>{{$post->content}}</p>
    </div>
    @endforeach
</div>

This would return all of the posts thats status = displayed.

janmoes's avatar

I get what you mean, but i'm thinking of something else, but for example if i also want to add images to the homepage and also show posts i now need to included 2 models within the controller to get data, i'm actually looking for a way that i can save a lot of custom data within a json object saved in just 1 database table column, so if the object is called by $data that i can just print $data->location etc

ollie_123's avatar

Dude, yeah it may be 2 models but you'd be working with Eloquent. So its only 2 queries for 2 different types of data.

//DashboardController
use App\Post; // This is your model

public function show() 
{
    $posts = \App\Post::where('status', 'displayed')->get();
    $gallery = \App\Gallery::where('status', 'displayed')->get();

    return view('your_page_name', compact('posts'));
}

and again 2 foreach loops for the data you wish to display.

You mentioned that you want to store all of your data in one column on a table? I would advise against this as it will cause you all sorts of nightmares when decoding & trying to display the data in the format that you want.

You would be better off separating your data so that its manageable & scalable.

janmoes's avatar

Yeah you got a good point. One last question, if i just want to display a location or phone number, which is editable. How would you save a a single value like that in the database?

ollie_123's avatar

There are a couple of different ways of doing it but AJAX will probably be your best bet.

janmoes's avatar

Yeah i practically need an online saved environment where i can store single values, which aren't repeatable. for the rest i can just use resource controllers like you said

Please or to participate in this conversation.