problem in laravel route on tackling the response of payment gateway - laravel

I'm using laravel and integrate the payment gateway.when i send the post request then after success or cancellation ,it redirect the referece id like this
http://localhost/multi_vendor/user/paypal/return?flwref=FLW-MOCK-d4f7572650fbe61ecff7fb17a7129859&txref=rave-bxw7c98dymo8so0kwosco0wwscs8ogc
so how can tackle it in laravel?
I made route for this
Route::get('/paypal/return', 'User\PaypalController#payreturn')->name('user.payment.return');

You can create a route as you write above:-
Route::get('/paypal/return', 'User\PaypalController#payreturn')->name('user.payment.return');
Then in User\PaypalController Controller method payreturn, you can do as following:-
<?php
namespace App\Http\Controllers\User;
use Illuminate\Http\Request;
class PaypalController extends Controller
{
public function payreturn(Request $request)
{
//Here you can get the response request values
$ref = $request->flwref;
$TxRef = $request->txref;
}
}

I also didn't understand well your question, but let me try.
Possible appointments:
if your route is like localhost/multi_vendor/user/paypal/return, you must represent all steps in route file, something like Route::get('/multi_vendor/{user}/paypal/return,[...]). If you are already using somethink like it or a group with prefix, ignore it;
if you wish to redirect, you could use return redirect('yourCompleteUrl') in your controller or in route file;
if you wish to retrieave the parameters Tim Lewis anserwed what you need:
public function payreturn(Request $request)
{
$flref = $request->input('flref');
$txref = $request->input('txref');
}

#darnish manzoor just add your url callback rootverto verifycrsf token
if your redirection url is /ravecallback, just add it and it will stop giving you method not allowed
protected $except = [
'/ravecallback'
];

Related

Laravel: Multiple Route to Same Controller

May I know how can I make just a single route so I don't have to repeat it? Thanks in advance.
Route::get('/url', 'CtcFormController#index' )->name('CtcForm.ch');
Route::post('/url/submit', 'CtcFormController#submit')->name('CtcForm.submit');
Route::view('/url/submitted', 'form.submit')->name('CtcForm.submit');
Route::get('/url2','CtcFormController#store')->name('CtcForm.eng');
Route::post('/url2/submit', 'CtcFormController#submit')->name('CtcForm.submit');
Route::view('/url2/submitted', 'form.submit')->name('CtcForm.submit');
As per your given example, you want to handle the variable part of the route which is /url/ and /url12/. Yes! you can handle there both different route using a single route in ways:
Use route variable to handle dynamic url values i.e. url, url2,url3...url12 and so on.
Route::get('/{url}', 'CtcFormController#index' )->name('CtcForm.ch');
Route::post('/{url}/submit', 'CtcFormController#submit')->name('CtcForm.submit');
Route::view('/{url}/submitted', 'form.submit')->name('CtcForm.submit');
Now in your controller methods handing above routes receive extra parameter $url like:
In controller CtcFormController.php class:
public function index(Request $request, string $url) {
//$url will gives you value from which url request is submitted i.e. url or url12
//method logic goes here ...
}
Similarly, method handling /{url}/submit route will be like:
public function submit(Request $request, string $url) {
//method logic goes here ...
}
Let me know if you have any further query regarding this or you face any issue while implementing it.

routing with model and variable

I am trying to test a custom email verification code with route model binding, when 2 wildcards are used, laravel always returns a 404.
this is my route in api.php
Route::get('/verify_contact_email/{id}/{hashed_key}', 'CustomEmailVerifyController#verifyContactEmail');
this is the controller with verifyContactEmail
public function verifyContactEmail(UserContactEmailVerify $id, $hashed_key) { return $id; }
when I remove the wildcard {hashed_key} and the $hashed_key, the model shows. I read up on laravel routing documentation, there is no mention of multiple wildcards or passing variable thru URL. Am I doing it wrong? Any help is much appreciated.
You should try this
public function verifyContactEmail($id, $hashed_key) {
$id = UserContactEmailVerify::findOrFail($id);
if(isset($id)){
return $id;
}
}
There is no problem with the route model binding or controller functions. The problem was discovered that routes do not work with hashing or bcrypt, str_random(20) has replaced the verification code instead of bcrypt.

How Redirect to Other Method in one Controller with Request in laravel?

in my case i have a route for get and set API.
if user want to get something i don't want to check Validation. but if his wants to set, i Want to Check Request input validation with Request file.
look:
class EventsController extends Controller
{
public function get(Request $request)
{
if( empty($request['data']) )
{
// Return Request.. is ok
}elseif( !empty($request['data']) && $request->has('data.id') )
{
// so User want to insert in database and I want to check
// Validation with Request file in the method
// How can i Do this?
call $this->store( // send Request to that for Validation )
}
}
public function store(ValidateInput $request)
{
// Insert into Database
}
}
Note: in the getMethod i don't want check validation but in store method i want!
1- i don't want to use other Route and i want do Both in one Request and Route
2- my main Question: who can i change Method in Controller and pass Request to that!
you can try something like :
//Calling a method that is from the EventsController
$result = (new EventsController)->store();
but the best approche is to split them into two methods as #Sandeesh said

How to get controller action by passing URL in laravel

I searched more time to find how to get the controller method name by passing the URL but not found my expected answer. I want to make a method where I will pass a URL and it will give the corresponding controller action like as below but I can't figure out.
I found a helper which just return the current URL's action which is Route::currentRouteAction()
If a route in my application like as Route::get('/abc', 'YourController#method') which will generate the url http://example.com/abc
then how can I get the YourController#method by passing http://example.com/abc
function getAction($url){
//what will be logic?
// return like App\Controllers\MyController#method
}
I have to make a custom permission system where I need it for show and hide the menu by checking the URL of each menu.
Within your controller you can do the following:
<?php
use Illuminate\Routing\Router;
use Illuminate\Http\Request;
public function index(Request $request, Router $route)
{
$action = $router->getRoutes()->match($request)->getActionName();
// action should be what you're looking for.
}
You can try this if you want to:
Route::get('/the/url', 'YourController#method');
Every time anything calls the URL in the route, your method will be called.
You don't need to navigate to that url to call your method, it could be called by a form action, or a buttons action and just execute your method.
Edit:
url is your url as parameter (plain route)
import this:
use Illuminate\Routing\Route;
this is your function:
public function method(Route $route, $url)
{
$routes = \Route::getRoutes()->getRoutes();
foreach($routes as $r){
if($r->getUri() == $url){
$youraction= $r->getActionName();
dd($youraction);
}
else{
dd('does not exist');
}
}
}
Tested.

Laravel search by dates not working

I need to search by date. My route definition:
Route::get('/calendar/days?day={date}', 'HomeController#getDays');
In the controller method I have this:
public function getDays($date)
{
$articles = Article::where('published_at','=',$date)->get();
dd($articles);
}
When you click on the link on the image below I get a NotFoundHttpException.
The link is generated using JS. Could this be the problem?
You should not be defining query string parameters in the route definition. For a detailed explanation on why that is see this answer. So in your case you have two options:
1. Remove the ?day={date} from the definition:
Route::get('/calendar/days', 'HomeController#getDays');
And in your controller access the request input parameter like so:
use Illuminate\Http\Request;
...
public function getDays(Request $request)
{
$date = $request->input('date');
$articles = Article::where('published_at', '=', $date)->get();
}
2. Modify your route definition to something like this:
Route::get('/calendar/days/{date}', 'HomeController#getDays');
The controller code you have now needs no change in this case, however the link you generate via JavaScript would need to look like this:
9

Resources