I can develop Laravel packages and can made custom blade, migration, model, controller, route from a package. But my question is specifically on how can I plug onto a default CRUD that was already built, from a package to modify that.
I started my PHP career from CMS like WordPress, Drupal, and then CakePHP, Laravel. Starting with procedural coding, OOP was a learning curve and is still a learning curve for mine. But scouring different platform made me understand that, the same thing can be achieved in different ways.
With WordPress plugin development experience, it's easy to extend functionality using action and filter hooks. With a core functionality like:
Fetch form data (3 fields)
hook here <---
Load form data (3 fields)
Submit form data (3 fields)
hook here <---
Save form data (3 fields)
can be easily modified from a plugin like:
Fetch form data (3 fields)
action hook <--- (hooked - added 2 fields)
Load form data (5 fields)
Submit form data (5 fields)
filter hook <--- (hooked - added data of 2 additional fields)
Save form data (5 fields)
But when in Laravel, I want to achieve a similar feature being in Laravel scope, how can I?
I understand the use of #yield('my_hook') is similar to the action hook in WordPress. But found that, if I hook multiple onto #yield it's getting overridden.
I found several packages like eventy with a similar approach of action and filter hook of WordPress, but I'm actually asking for a Laravel approach to the issue.
I came across to the Laravel Events, is that the solution to hook like an action hook in WordPress? And the filter hook, I think we can extend a model to modify its behavior. But I'm afraid, these are all the imagination, and might not be the reality. I don't have any idea on that.
Can I get some enlightenment onto this issue?
Both WordPress and Laravel are frameworks on a whole different level, so comparison might be difficult.
In Laravel you have tools to control the output (html page). #yield is an example, when you are using Blade templates.
Furthermore there are methods to hook on certain events within the execution of the framework (Laravel Events).
In Laravel you are working in a Model-View-Control setting meaning that you can/should:
Make a Model of every data-entity you are using and give it the responsibility to do it's own work. See also https://laravel.com/docs/5.8/eloquent#events for hooks
Make Controller methods for every action you want to execute from the front-end. It is a good practice to keep these methods as short as possible. e.g. max 10 lines.
Make sophisticated templates using the Blade Template engine
Hope this will help.
Related
I am building a Laravel Inertia eCommerce SPA, and I am trying to add several filters to the products page, using the watch method that calls up a partial reload on change.
The problems are three-fold:
I don't know the correct syntax to have the watcher keep an eye on the whole filters prop, rather than individual filters.
The individual filters that I do manage to apply do not refresh the page content after being switched off, only on.
Lastly, I don't know how to check if other filters are active, and prevent conflict when writing filter queries.
Here is my Vue component https://i.imgur.com/dxt1e5n.png and https://i.imgur.com/2VThbWv.png
And the route in question https://i.imgur.com/rLwoW9g.png
Any pointers that anyone might be able to provide would be very helpful.
I'm developing a personal project using Laravel with Inertia.js. I tried retrieving data from back-end to front-end through HandleInertiaRequests Middleware. I was wondering how will malicious people could get advantage of the data I show up in front-end. Inertia.js webpage discourages retrieving sensible data in this way, but I can't figure out how that will be possible. I apologize if my answer sound a little naive, still pretty new to Laravel ad never used Inertia before. Thanks for your time!
The HandleInertiaRequests Middleware is nothing but a way to merge data into the array that will be available to your JavaScript components (Vue, React, Svelte) on the client side.
It is just a way to avoid repeating yourself on every controller for things that you'll probably need on a lot of pages. For example, instead of getting the data for a Menu component on every controller, you do this only in the HandleInertiaRequests Middleware.
So, they only warn you to be careful with what type of data you put into it. For example, you probably don't want to pass the user password through this in the same way you wouldn't do that using a Blade view instead of Inertia.
I'm attempting to design a project in Laravel. I ran the following command to initialize the project: "laravel new demo --jet". When prompted to choose between inertia and livewire I chose livewire as I've heard better things about it.
A little back story, I'm about 2-3 weeks into learning Laravel and I've never used livewire before, although I am very familiar with using Javascript and am very experienced with Vue.js. I've looked elsewhere for a solution to my problem but now I'm not quite sure if Laravel even supports exactly what I'm looking for.
TL/DR:
I'm wondering what the best practice would be for rendering child components on a page. I would like to create a dashboard that has several options to choose from on the left side of the page. When a user selects an option, I'd like for a corresponding component to appear in the center of the page. If a user were to select a different option, the original child component would disappear and a new corresponding child component would become visible.
Ideally, I'd like to avoid using the router for this, although that might just be because I'm not entirely comfortable with using it. I do understand it's pretty heavily integrated into the Laravel workflow. As I mentioned, I'm used to using Vue where you can easily integrate JS functionality into your html and use conditional statements to hide/show child components without changing routes.
If anything I've said above is causing any confusion, let me know. Thanks.
P.S. If anyone has any good resources for learning livewire & laravel together please let me know about them! Laracasts has been great but I think Laravel recently updated their auth scaffolding and it's causing some confusion for me.
im trying to create a Single Page Website with DurandalJS in the frontend and Laravel as the Backend. Do you think this is a good Idea?
If yes how would I do the following:
What would your recommendation for the basic interaction between both frameworks be?
Would you rather have all the computation done in JS instead of Laravel sending calculated and styled returns?
How Do I setup Laravels controller in order to only get dynamic Data for, say a Div, instead of a whole page?
How can I adjust the browser URLs?
I hope I was specific enough, thank You in advance.
Laravel does not actually care about what framework you use to build the Frontend. Laravel is just a framework that helps you build your application with. It gives you great advantage with respect to the time spent and effort.
You can use any frontend framework that you want to build your app with. I have actually not used Durandal, but from the first look of it here is my opinion.
Durandal is built on top of jQuery, knockoutJS and requireJS. It also has a MV* architecture in place with support for eventing as well. So you could basically define routes on Laravel and initiate the communication between both the frameworks through events and ajax. Again this completely depends on the functionality that you are building.
In the overall flow of your app, consider Laravel as a Model that just gives data from a source to your app and Durandal as your views and controllers. This way, it will keep your data flow cleaner and easier to build. Computation of your functionality depends on how important and secretive the app is. If there are functionalities/implementations that you need to be secretive about, you can keep it on Laravel and just send computed data to Durandal. If its a web app that you are building, then keeping all implementation on the JS is just a right click away from knowing what and how you have built it. One can just see how the implementation is done just looking at the Javascript source of the web app. If you are building Mobile Device App, then the case is different.
Take a look at Restful Controllers. Will give you an idea on how to setup controllers to return only data. But if you need to return the div itself, then you can make use of the Basic Controllers of Laravel to perform them.
You can setup cleaner routes for the browser URL's. Take a look at Laravel Routing
I'm new to django and I'm trying to figure out how to create custom actions inside admin site.
Let's say I want to create some sort of custom form with fancy ajax based ui.
What I would normally do in .NET/PHP/Ruby is prepare some js code and a service that will be called via ajax and return json or even html.
A more concrete example could be an auto complete box to manage a many to one relationship. What should I do to build such a system inside the django admin site? (I know there are a couple of ready to use solution for this. But I'm not interested: just for study purposes).
In this particular case (a fancier widget), ModelAdmin has several useful hooks like ModelAdmin.form and ModelAdmin.formfield_overrides.
Creating a custom Django Form Widget is more elegant, but if the widget is pure JS (like many jQuery widgets), most of the time it is not worth - just override the change_form.html admin template for the Model in question.
You can easily change the form and the template of the ModelAdmin.
So you're free to inject any CSS and JS you like. Take look at this presentation to get the basic idea.