Shown Success / Failure message after laravel admin action is executed - laravel-5

I want shown message in laravel admin panel after action is executed or when i will redirect to listing or other page.
I have configured the laravel-admin package so inbuilt laravel module message showing in toaster so i want to need similar to this.
So can you please let me know if anyone know about this.
Thanks.

You can use this in case for redirecting:
admin_toastr(__('Outlet created successfully'));
return redirect(admin_url('/'));
Or in case of return after any action execution you use like below
public function sale(Request $request,Content $content) {
return $content->withSuccess('Success', 'Fund has been transfered successfully');
}

Related

Laravel export downloadable CSV file

I am trying to write an endpoint which exports the data from the users table i currently have into a CSV file which is downloaded upon clicking of a button. I have setup the controller, routes, export file, and added in the button within the view but everytime i go to click the button it just directs me to the admin/user/export then gives me a 404 but shouldnt it just stay on the same URL then just add the file to my downloads file?
This is the package i am using for Laravel
https://github.com/maatwebsite/Laravel-Excel
web route
Route::get('users/export', 'Admin\UserController#export')->name('users.export');
UserExport
class UsersExport implements FromCollection
{
public function collection()
{
return User::all();
}
}
Controller Function
public function export()
{
return Excel::download(new UsersExport, 'users.csv');
}
Summarise problem:
Everytime i click the button on the view page it directs to admin/users/export then gives me a 404 when i want it to just download the CSV file for the users.
Some help to see where i am wrong would be helpful!
Thanks.
The problem is that two of your routes conflict with each other.
Given the following two routes:
Route::get('users/{user}', 'Admin\UserController#show')->name('users.show');
Route::get('users/export', 'Admin\UserController#export')->name('users.export');
Currently Laravel assumes that when you are trying to access users/export you actually want to access users/{user} with export as the route parameter {user}.
Making sure that users/export is registered before users/{user} should solve your issue:
Route::get('users/export', 'Admin\UserController#export')->name('users.export');
Route::get('users/{user}', 'Admin\UserController#show')->name('users.show');

Dompdf Laravel Test

I am having problems resolving this issue. I want the user to be able to download a report when pressing the button. I keep on getting Action not defined, and if I change my route it will simply not load the app.
Any help would be appreciated.
/************View***************/
<button>Download PDF</button>
/*************Controller****************/
public function pdf($id){
$report=Report::findorFail($id);
$pdf = PDF::loadView('reports.show', compact('report'));
return $pdf->download('server_report.pdf');
}
You need to have your action defined in a route.
For example:
Route::get('pdf','ReportController#pdf');
Also, make sure that if ReportController has a resource route then the pdf route goes above it.

Preview Laravel Mail before sending

I want to edit my mail and change everything, if I want, as shown here.
Ive imported my file and created a test route to view the page:
use Illuminate\Mail\Markdown;
Route::get('/mail/html', function () {
$markdown = new Markdown(view(), config('mail.markdown'));
return $markdown->render('vendor.mail.html.message'); // or ..markdown.message
});
However, Im having variable errors for #slot. How to view my change/see what the mail looks like before sending? Another package for that?
Thanks
To preview your email in browser please add below code to route
Route::get('preview-notification', function () {
$markdown = new \Illuminate\Mail\Markdown(view(), config('mail.markdown'));
$data = "Your data to be use in blade file";
return $markdown->render("path-of-your-templete-blade-file", $data]);
});
and you will be access your templete using
http://your-application-url/preview-notification
This is the recommended way by the Laravel community
kunal has a nice quick solution and that's how I used to do it. But now I use mailtrap.io to test emails because it allows you to replicate the whole process of sending an email.
Create a (free) account with mailtrap.io.
Add your mailtrap username and password in .env file.
By the way, Laravel is already configured to use mailtrap by default, so it is their recommended way to test emails.
Watch how Jeffrey Ways does it in his lesson:
Laravel 5.4 From Scratch: Sending Email
https://laracasts.com/series/laravel-from-scratch-2017/episodes/26
If you want to test in locally. You can put echo command in blade file at end and put die; this way you can test.Suppose you have test-email.blade.php
test-email.blade.php // file name
This is tets mail
<?php echo "test"; die; ?>
Hope it helps!

Can't persist Auth::login with Laravel 5

I'm trying to manually log in a user within a Controller or a Route. This works during the scope of the page, but it doesn't persists.
Here is my code :
Route::get('check', function (){
if (Auth::loginUsingId(1)) { // User #1 is existing in the DB
return redirect()->intended('/check2');
}
});
Route::get('check2', function (){
dd(Auth::user());
});
And I got : null on my /check2 page
Can someone give me a quick hint?
PS: I tested the default Auth Laravel system and it works.
Thank you very much!
The issue was simple. On Laravel 5.2, you need to wrap all concerned Routes inside the middleware "web" in order to play with Authentification.
Thanks all.

Zend Framework non-existent controller redirects to home page?

When I type an invalid url (non-existent controller), it displays the homepage rather than return a 404 Page Not Found page. Does anyone know the possible reason?
Thanks
Have checked if there is any plugins are registered in the bootstrap and if is it configured to catch the exceptions or set any ACL mechanisms.
Also check the error controller too. may be there is some forwarding methods implemented there.
Hi i've had the same problem and i now know how to fix it:
within the bootstrap have the following init
function _initModules()
{
$this->bootstrap('frontController') ;
$front = $this->getResource('frontController') ;
$front->addModuleDirectory(APPLICATION_PATH . "/modules");
$front->setParam("useDefaultControllerAlways", false);
}
Setting 'useDefault....' will use the default controller when a 404 occurs.
You should also make sure your error controller is setup correctly

Resources