Getting CRUD data from laravel backpack to a new blade view page - laravel

I'm new to laravel backpack so what did is created a CRUD of title and description. And everything in admin panel works fine, but now I need to get that data to another blade view file through a controller like in a vanilla laravel but I cant seem to find how to do it.

If I understand your question correctly, there's absolutely NOTHING special you need to do - just do it "the normal Laravel way", by using your Model to query the database. It's usually something like Career::all() or Career::find($id) or Career::where('something', $value)->get(), depending on what you need to fetch from the database.
That's because Backpack uses your existing Eloquent Models, or creates the models if you don't have them already (usually in app\Models). So whenever you create/edit/delete an entry using the Backpack interface (aka CRUD), what Backpack does is use that Model to interact with the database. If you want to interact with the database, you should do the same thing - use the Model. That's the expected and recommended way of doing things in Laravel. To have Models for all your major database tables and do most (or all) of your interactions with the database using the Eloquent Models.

You can use view like this:
view('crud::show');
list, create etc.
all available files, you can find here: vendor/backpack/crud/src/resources/views/crud
If you want to override the template, please copy vendor template to your project
vendor/backpack/crud/src/resources/views/crud/show.blade.php > resources/views/vendor/backpack/crud/show.blade.php

Related

Changing the author name In already built plugin in octobercms

I am building plugins that do simple CRUD in octobercms but the url in the backend has author name in it. I want to change it to something reliable to the website like max/home/home to page/home/home
Search for use max/home/home and replace with page/home/home inside model and controllers.
Rename the plugin folder with new author name.
You dont need to rebuild new tables, just make sure the models have proper table name.
On your theme, don't use builder to query results. Use the Models as done in laravel eloquent.

Laravel automated view generation from models

In Laravel, I can create models and controllers automatically from the command line using
artisan
However, There is no command to generate views automatically based on the the model for CRUD operations. Wonder if there is a tool that would make this out of the box. I imagine this:
php artisan make:view model
and then I have all my views ready. I tried to search online but could not find a proper tool: LarvelCodeGenerator, and others...
Have you taken a look at Laravel View Generator.

laravel-voyager custom views for role

Laravel Version: 5.26.27
Voyager Version: 1.1.3
PHP Version: 7.2.1
Database Driver & Version: MySQL 5.6.38
Description:
I'm new to Voyager but have already managed to create tables, populate them and configure their access privileges for BREAD.
But I need one option to see in the posts the custom roles can view just himself post, I see one option
#foreach($dataTypeContent->where('author_id','=', Auth::user()->id) as $data)
But this code modifies all views because is in the view. I need some more generic in the model
Is this possible with Voyager or it calls for custom code?
Thanks in advance!
Your question is a little confusing to read, but it sounds like you're asking if it's possible to override Voyager views or add custom views and the answer is, yes you can.
They have a video here: https://laravelvoyager.com/academy/views/
and written documentation here: https://voyager.readme.io/docs/overriding-views
The short of it is, create a directory resources/views/vendor/voyager/slug-name where slug-name is the slug for the corresponding table view you want to override. Put an edit-add.blade.php file in that folder along with a browse.blade.php file. I would just copy Voyagers default view logic into those files and then modify them to suit your needs.

How to "connect" Laravel project with Craft 3 CMS Website

I've developed an app which fetches data from an API based on Laravel 5.5. The marketing landingpage of the app is based on Craft CMS Version 3. The marketing website and the API and the databases of both systems are running on the same server.
I want to generate landingpages for each row of table X of the Laravel database.
www.website.com/awesome-landingpage-about-{slug}
What is the best approach to realize this?
I don't want to fetch the data directly from Laravel's database
I don't want to synchronize the Craft CMS database with the Laravel (add/remove the rows from the laravel's database as entries to Craft)
It would be awesome to be able to have an entry-type "Landingpage" where we can optionally create a landingpage, referencing to an ID of the laravel table and add additional content for the landingpages.
Would be a JSON-API from Laravel to Craft CMS Plugin a good performant idea?
One option would be to use a Dynamic Route and just fetch the data from 127.0.0.1 (because same server) from the template file? Or is there a smarter way in Craft CMS?
Let's start of by:
"I don't want to fetch the data directly from Laravel's database"
I'm assuming you don't want to write code in CraftCMS to access another project's database. Good. IF you plan on having them do seperate jobs and use Laravel API for fetching data alone, let it handle it's own database.
"I don't want to synchronize the Craft CMS database with the Laravel (add/remove the rows from the laravel's database as entries to Craft)"
So, this is my question:
You want to be able to create landing pages based of Laravel's rows alone or based of Laravel's database row's and CraftCMS's?
It all comes down to how well you want to abstract both frameworks.
I would probably tell laravel to accept requests from authenticated user (a CraftCMS User) or from localhosts (from within the machine alone) and I'd create endpoints to add/remove/edit/get data at my disposal. I'd then fetch rows from Laravel and combine with my own (assume I'm the CMS).
Even in an intranet network, the request to tell laravel to access the database is longer than to access the database from CraftCMS, so you should expect a dependency between the two projects.
For point 3, you'll have to store information on each database about something. On CraftCMS's to store at least the ID's it's going to request to laravel and laravel will have to get an endpoint where it can insert new stuff, if you're planning on having additional content there.
I'm not entirely sure if I got the idea you're trying to show when you say "add additional content for the landing pages" but I'd try to keep it simple and abstract it's uses, Laravel to store this 'information' that the CMS shouldn't handle in the first place (or you can work out some extra tables and import them to the other database).
Impact performance? Depends on the ammount of data you've got

How to generate scaffold RESTful view templates in Laravel like how RoR does?

Rails generates a folder of view template scaffolds when you run the cli command rails g controller User.
It will have view template scaffolding for create_user.html.erb, update_user.html.erb, list_user.html.erv....etc etc.
Is there anyway to have that same functionality in Laravel whether via a library, some included function, or a custom generator(or some other way)?
I'm using Laravel 5.4 if that makes a difference.
Since you're looking to generate views, I assume you're talking about a CRUD admin panel rather than an API. I highly recommend Laravel CRUD.
https://github.com/Laravel-Backpack/CRUD
This will allow you to create a model, controller, all routes, views etc with the command php artisan backpack:crud Model. It's super easy to use, but you'd want to probably start your project fresh - it assumes you're using it for the whole admin section, not just the views.

Resources