When click on back button on browser it can't display back page in php laravel - laravel-5.4

Problem:
I want to clear project history, when back button clicked by user on browser.
Technology using:
I am using php laravel-5.4.

Yes I got solution for my problem, I created middleware and used in route file, i got solution.
my middleware code is this,
namespace App\Http\Middleware;
use Closure;
class PreventBackHistory
{
/**
* Handle an incoming request.
*
* #param \Illuminate\Http\Request $request
* #param \Closure $next
* #return mixed
*/
public function handle($request, Closure $next)
{
$response = $next($request);
return $response->header('Cache-Control','no-cache, no-store, max-age=0, must-revalidate')
->header('Pragma','no-cache')
->header('Expires','Sun, 02 Jan 1990 00:00:00 GMT');
}
}

Related

How to set multiple cookies with one response in Laravel?

I am trying to send multiple cookies with one response. I have an array with cookies named
$cookies
What would be an alternative of the following example if I have an array with values instead of specific values
return $response
->withCookie(cookie()->forever('region', $region))
->withCookie(cookie()->forever('somethingElse', $somethingElse));
I have tried the following code but it does not seem to work.
$response = $this->response(200, 'Successful');
foreach($cookies as $cookie){
$response = $response->withCookie($cookie);
}
return $response;
Just save the cookies via the Cookie::queue() method.
Then you can access the cookies anywhere via the Cookie::get() method afterwards.
You won't need to add them to the response if you do it this way, and they will still be accessible inside of views etc.
Try adding this function inside "vendor\laravel\framework\src\Illuminate\Http\Response.php". The function adds and removes multiple cookies in one response.
/**
* Add cookies to the response.
*
* #param Array of $cookie
* #return \Illuminate\Http\Response
*/
public function withCookies(Array $cookies)
{
foreach($cookies as $cookie)
$this->headers->setCookie($cookie);
return $this;
}

How to get real-time data on new data insert into MySQL db

I am using Laravel and pusher. Pusher is working good. But I want to know how can I get data when I will insert new data into database?
Process is if someone push/insert data on the table, then those data will automatically show without reloading the page.
Can anyone explain it? or give me any documentation or video link about it?
What you need are Broadcast Events.
Let's assume that you are inserting a Post and you want all users to get notified about a new post, therefore refresh the posts table index.
All your users should be subscribed to a presence channel, but you could use private or public channel. IMO, presence channel works better for this scenario since you are dispatching just 1 event for all users instead of 1 event per user in case of private channel
In your store function in PostController.php you dispatch the event once Post has been created:
use App\Events\PostCreated;
public function store(Request $request)
{
// Insert new post
$post = Post::create($request->all());
// Dispatch broadcast
PostCreated::dispatch($post);
return $result;
}
Then in your PostCreated.php Event, you send the post itself as the event payload:
<?php
namespace App\Events;
use App\Models\Post;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
class PostCreated implements ShouldBroadcastNow
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $afterCommit = true;
public Post $post;
/**
* Create a new event instance.
*
* #return void
*/
public function __construct(Post $post)
{
$this->post = $post;
}
/**
* The event's broadcast name.
*
* #return string
*/
public function broadcastAs()
{
return 'post.created';
}
/**
* Get the data to broadcast.
*
* #return array
*/
public function broadcastWith()
{
return $this->post;
}
/**
* Get the channels the event should broadcast on.
*
* #return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new PresenceChannel('posts');
}
}
Now you need that all users subscribe to the right channel. Assuming, again, that you are using laravel echo, this is how I do it within a Vue Js app by joining a presence channel posts and listening for post.created event.
this.echoInstance.join('posts')
.listen('.post.created', (post) => {
// Do something like refresh table
// or insert `post` object directly in posts array
})
Since you didn't provide any code, this is a generic sample. Next time, please share what you've done so far.

These credentials do not match our records.in Laravel 6

I using laravel 6 Suddenly when I'm trying to log in I on the email field.
These credentials do not match our records.
I have checked my database and entered email is correct and I am getting this error
also, I search a lot about this problem but I didn't get any solution
NOTE: I already tried this function but also it doesn't work
public function setPasswordAttribute($password)
{
$this->attributes['password'] = \Hash::make($password);
}
Login Controller
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
class LoginController extends Controller
{
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/
use AuthenticatesUsers;
/**
* Where to redirect users after login.
*
* #var string
*/
protected $redirectTo = RouteServiceProvider::HOME;
/**
* Create a new controller instance.
*
* #return void
*/
public function __construct()
{
$this->middleware('guest')->except('logout');
}
}
Try this bcrypt
public function setPasswordAttribute($password)
{
$this->attributes['password'] = bcrypt($password);
}

Insertion of data into db not working for Laravel 5.4 on server(working on localhost)

I am trying to deploy a project involving basic CRUD operations using Laravel 5.4 on cpanel server.
I am trying to insert an Item into my Database. My updation and deletion code seems to be working but insertion isn't.
Please note that on Localhost everything is working but on the server Insertion isn't.
Here's the Code and different php files.
My controller is gendersController which has all the CRUD functions.
Web.php(gender route)
Route::resource('/genders','gendersController');
Create.php (View on which we are seeing a form with a single field and submit button)
#extends('layout.app')
#section('body')
<br>
<a href="/genders" class="btn btn-info" >Back</a>
<div class="col-lg-4 col-lg-offset-4">
<h1>{{substr(Route::currentRouteName(),8)}} item</h1>
<form class="form-horizontal" action="/genders/#yield('editid')"
method="POST">
{{csrf_field()}}
#section('editMethod')
#show
<fieldset>
<div class="form-group">
<div class="col-lg-10">
<label>Gender Type <input type="text" class="form-control"
name="gendertypes" id="gendertypes" value="#yield('editgendertypes')">
</label>
<br>
<button type="submit" class="btn btn-success">Submit</button>
</div>
</div>
</fieldset>
</form>
#include('partial.errors')
</div>
#endsection
gendersController.php (genders Controller)
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\gender;
use DB;
class gendersController extends Controller
{
/**
* Display a listing of the resource.
*
* #return \Illuminate\Http\Response
*/
public function index()
{
$genders= gender::paginate(1000);
return view('gender.index',compact('genders'));
}
/**
* Show the form for creating a new resource.
*
* #return \Illuminate\Http\Response
*/
public function create()
{
return view('gender.create');
}
/**
* Store a newly created resource in storage.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$gender = new gender;
$this->validate($request,[
'gendertypes'=>'required',
]);
$gender->gendertypes=$request->gendertypes;
$gender->save();
session()->flash('message','Added Successfully');
return redirect('/genders');
}
/**
* Display the specified resource.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function show($id)
{
return $id;
}
/**
* Show the form for editing the specified resource.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function edit($id)
{
$gender = gender::find($id);
return view('gender.edit',compact('gender'));
}
/**
* Update the specified resource in storage.
*
* #param \Illuminate\Http\Request $request
* #param int $id
* #return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
$gender = gender::find($id);
$gender->gendertypes=$request->gendertypes;
$gender->save();
session()->flash('message','Updated Successfully');
return redirect('/genders');
}
/**
* Remove the specified resource from storage.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function destroy($id)
{
$gender=gender::find($id);
$gender->delete();
session()->flash('message','Delete Successfully');
return redirect('/genders');
}
}
Here are the images
Main View(this is were all the data from the database gets displayed. Also has the add button
url: domainname/genders
![Genders view]: http://imgur.com/a/mqEq3
Add new Gender view
url: domainname/genders/create
![Create View]: http://imgur.com/a/9Houv
After adding for some reason, I get redirected to the main view page without any insertion being made into the database (because of this the new data is not displayed on the main view page)
Can't find the error!!
Check the url your form is posting to. Because you hardcode the urls in the forms /genders/x instead of using named routes with generated urls relative to your installations doc root, the form will post to
http://your.domain.com/genders/
instead of
http://your.domain.com/some_folder_name/genders
That's why on localhost everything works fine, but once you deploy it in a subdirectory it will not.
You are using a resource route, so route('genders.store') should work just fine in your view. Check available routes and their names through php artisan route:list.
Sidenote: Try and avoid placing the files outside of Laravel's public path in a public_html directory (or a publicly subdir for that matter). There's a reason why some directories and files are outside of the document root.

Find all methods without documentation (preferably inside a directory) in PhpStorm

Is there a way to find all the methods without documentation in PhpStorm 10? What I can think of now is using regex, but I don't know how reliable it would be.
Code Inspect/PHPDoc section doesn't list any of them.
Ex:
Do not find this:
/**
* This method does something.
*
* #param int $name A parameter
*
* #returns array An array of something
*/
public function methodName($name)
{
return array();
}
Find This:
public function methodName($name)
{
return array();
}
Or maybe even this:
/**
* #param $name
* #returns
*/
public function methodName($name)
{
return array();
}
The name of the inspection you're looking for is "Missing PHPDoc comment", it's disabled by default. You can use Code | Run Inspection by Name or Code | Inspect Code to find all of the occurrences. Using these tools you can easily configure the desired scope.