You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi! Here are some features that i already implemented in my projects. If there is interest in them, i'm happy to implement them properly and create pull requests. Feedback please @yajra
1. Return selected columns
Problem: I want to process more columns than i want to display in the frontend. For example we have a Product model that has internal attributes like margin/fees, which are required for calculating the price. In this case i have to load the whole model (no select() restriction), but i don't want the internal attributes to be visible in the ajax request. The problem get's worse when loading nested relations, which are all included in the response.
Solution: Function to select which columns of the eloquent model should be included in the ajax response. Columns that were added via addColumn() are automatically included. In the following example, the whole Product model is available in the addColumns function, but only the id,name,description,price columns are returned in the ajax response.
Problem: I want to display custom errors (general as well as related to a field) in the updating or updated functions.
Solution: A CustomException class, which i can throw with the error message in the parameters. The frontend then shows the error message in production, bypassing the generic "Server Error" message.
publicfunctioncreating(Model$model, $data)
{
if ((newCarbon($data['start_date']))->floatDiffInYears(newCarbon($data['end_date'])) > 1)
{
// Specific error message (shown under the corresponding field)thrownewCustomException([
[
'name' => 'end_date',
'status' => 'The date range must not exceed 1 year',
]
]);
}
}
publicfunctiondeleting(Model$model, $data) {
if (!Auth::user()->hasRole('admin')) {
// Generic error message (shown in the footer)thrownewCustomException([], 'You are not permitted to delete this row!');
}
}
3. Action Column
Problem: I am adding action buttons in a last column "Actions" like Open Details, Edit, Remove, etc. For 2-3 buttons you can just add them via render method in raw html, but if you have many buttons it gets messy fast. Especially if you also have permissions for each button.
Solution: A easy to use actions column, in which you can add buttons with serverside/clientside checks for each button. The buttons get formatted pretty with a css grid, uniform spacing between them, responsiveness, auto-width, etc. This solution requires css code
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi! Here are some features that i already implemented in my projects. If there is interest in them, i'm happy to implement them properly and create pull requests. Feedback please @yajra
1. Return selected columns
Problem: I want to process more columns than i want to display in the frontend. For example we have a
Product
model that has internal attributes like margin/fees, which are required for calculating the price. In this case i have to load the whole model (no select() restriction), but i don't want the internal attributes to be visible in the ajax request. The problem get's worse when loading nested relations, which are all included in the response.Solution: Function to select which columns of the eloquent model should be included in the ajax response. Columns that were added via
addColumn()
are automatically included. In the following example, the wholeProduct
model is available in theaddColumns
function, but only the id,name,description,price columns are returned in the ajax response.2. Custom Exception
Problem: I want to display custom errors (general as well as related to a field) in the
updating
orupdated
functions.Solution: A CustomException class, which i can throw with the error message in the parameters. The frontend then shows the error message in production, bypassing the generic "Server Error" message.
3. Action Column
Problem: I am adding action buttons in a last column "Actions" like Open Details, Edit, Remove, etc. For 2-3 buttons you can just add them via
render
method in raw html, but if you have many buttons it gets messy fast. Especially if you also have permissions for each button.Solution: A easy to use actions column, in which you can add buttons with serverside/clientside checks for each button. The buttons get formatted pretty with a css grid, uniform spacing between them, responsiveness, auto-width, etc.
This solution requires css code
Beta Was this translation helpful? Give feedback.
All reactions