Current route showing null Laravel - laravel

I am new to Laravel. I am using Laravel 5.4. For some purpose, I need the current route. For this, I am using the following code in my controller.
$name = Route::currentRouteName();
dd($name);
But, its always showing null. Any help will be appreciated.

I don't know what's problem with your code but you can get URL of current route with following way as well,
$name = URL::current();
To view value you can dump $name,
dd($name);

You can try with following:
$name = Route::current()->getName();
dd($name)

Related

Laravel "\Request::route()->getName()" give null results

I'm using Laravel with Spatie Permissions package, and it's working fine!
I'm trying also to use the Authorizable trait for managing the Roles and Permissions.
The problem seems to be $routeName = explode('.', \Request::route()->getName());.
I expect to have from \Request::route()->getName() the result posts.index but I have null.
\Request::route()->getName() works only if I defined the property "name" into the route by using ->name('posts/index') (and the result is posts/index )
why \Request::route()->getName() is null in my app ? What I'm doing wrong ?
To get route name ,you need to use
$name = Route::currentRouteName();
and use Illuminate\Support\Facades\Route;
Request::route()->getName() works only for laravel < 5.*
you can use
Route::currentRouteName(); //use Illuminate\Support\Facades\Route;
but also you can get action of route by
Route::getCurrentRoute()->getActionName();
I'm not sure why are you getting this but the route must have ->name() (if you want to use route names) if it was not a resource route.

How can I use "prep_url" from codeigniter inside my View in Laravel?

I add the function "prep_url" from codeigniter to my laravel project like here:
Laravel add http to urls
If I do it in my Controller like this:
$website = example.com;
$url = prep_url($website);
and then in my view I can do it like this:
{{$url}}
it shows me this: http://example.com
so everything works :)
but I have a problem
I have the table users and there all users have a website
in my controller I do it like this:
$user = DB::table('users')->get();
return view('user/einzelansicht' ['user' => $user] );
and in my view I can show my user with
{{$user[1]->name}}
{{$user[1]->website}}
how can I use prep_url here?
because I already did this in my view:
{{prep_url($user[1]->website);}}
but it tells me semicolons are not allowed and without the semicolon it does not work
then I tried in my controller this:
$website = $user->website;
$url = prep_url($website);
but this doesn't work too
so how can I do this?
Maybe your "website" attribute is not a string.
Try
prep_url(json_encode($u[1]->website));

Laravel 5.2 HTTPNOTFOUNDEXCEPTION

I cant figure out what is causing this error. I have checked to see if the parameters are correct and they seem to be. Also if anybody has an alternative way to get all the parameters in the route rather than listing them all please do tell. I can't find another way.
public function savePaymentDetails(Request $request, $code, $message, $mPAN, $type, $exp, $name, $TxnGUID,
$ApprovalCode, $CVVMatch, $GT_MID, $GT_TRANS_ID, $GT_Val_Code, $ProcTxnID,
$session, $card_brand_selected, $CRE_Verbose_Request, $CRESecureID,
$trans_type, $content_template_url, $allowed_types, $order_desc, $sess_id,
$sess_name, $return_url, $total_amt, $submit, $ip_address, $customer_lastname, $customer_firstname)
{
$code2 = $request->get('code');
echo $code2;
echo $code;
}
The route
Route::get('return/{code}/{message}/{mPAN}/{type}/{exp}/{name}/{TxnGUID}/{ApprovalCode}/{CVVMatch}/{GT_MID}/{GT_Trans_Id
}/{GT_Val_Code}/{ProcTxnID}/{session}/{card_brand_selected}/{CRE_Verbose_Request}/{CRESecureID }/{trans_type}/{content_template_url}/{allowed_types}/{order_desc}/{sess_id}/{sess_name}/{return_url}/{total_amt
}/{submit}/{ip_address}/{customer_lastname}/{customer_firstname}', 'PaymentController#savePaymentDetails');
Here are the parameters returned by the URL that I need to get
/return?code=000&message=Success&mPAN=XXXXXXXXXXXX1111&type=Visa&exp=1218&name=test+visa&TxnGUID=6041323& ApprovalCode=VI0151&CVVMatch=M&GT_MID=672840408068703&GT_Trans_Id=016142173277748&GT_Val_Code=AACA&ProcTxnID=6041323&session=e91dd8af53j35k072s0bubjtn7&card_brand_selected=Visa&CRE_Verbose_Request=1&CRESecureID=gt153545888233SB&trans_type=+2&content_template_url=https%3A%2F%2Fexample.com%2Fpublic%2Ftemplate&allowed_types=Visa|MasterCard|American+Express&order_desc=6&sess_id=e91dd8af53j35k072s0bubjtn7&sess_name=session&return_url=https%3A%2F%2Fexample.com%2Fpublic%2Freturn&total_amt=1.51&submit=submit&ip_address=10.108.231.98&customer_lastname=visa&customer_firstname=test
The route rule you define actually match the url like this
code/message/mPAN/type/exp/name/TxnGUID/ApprovalCode/CVVMatch/GT_MID/GT_Val_Code/ProcTxnID/session/card_brand_selected/CRE_Verbose_Request/trans_type/content_template_url/allowed_types/order_desc/sess_id/sess_name/return_url/submit/ip_address/customer_lastname/customer_firstname
instead of
return?code=blab&blablabal=blab
You url dismatch any route you define , so a not found exception was thrown .
If you are trying to get all url parameters you can just write your route like that .
Route::get('return', 'PaymentController#savePaymentDetails');
And get parameters in your controller :
$parameters = $requests->all();
What's more , if you are trying to save something to your database , you'd better use the post method , you can find more When should i use post or get.

update record with codeigniter active record

In my controller, I am calling a model function with the following:
$this->sales_model->softdelete_order($this->input->post('ordernumber'));
what I want to do, in my model is
update Customer_Order_Summary set Deleted='1' where CustomerOrderID='123'
where 123 is $this->input->post('ordernumber')
My Model syntax is:
function softdelete_order($q){
$this->db->set('Deleted','1');
$this->db->where('CustomerOrderID', $q);
$query = $this->db->update('Customer_Order_Summary');
}
This is not working or outputting any errors.
The model is preloaded and the post information is posting and echoing correctly so purely a model syntax issue I think.
Help appreciated as always.
Thanks,
After
$query = $this->db->update('Customer_Order_Summary');
add
$this->db->last_query();
to see your query and you can repair it from there.
Try using
$this->db->set('Deleted',1);
If not working post your exact error

Zend getParams not returing url params

I have a query:
https://myaddress.ee/admin/usersearchajax?country=EE&query=arno
$this->_request->getParam('query');
returns: NULL
var_dump($_REQUEST['query']);
returns: string(5) "arno"
How to fix this problem? I mean how to get GET values with zend framework?
Lets assume i can't change the query string.
zend version 1.11.11
public function usersearchajaxAction(){
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender( true );
$userService = new Application_Services_User();
$userList = $userService->searchByName($this->_request->getParam('query'));
$this->_helper->json($userService->getArrayForAutoComplete($this->_request->getParam('query'), $userList));
}
I found the problem, there was and override of $_GET variable in my project.
So it is fix now. thank you all for reading and thinking about this
instead of
$this->_request->getParam('query');
use this
$this->_getParam('query');
there is no need to use request action helper in Action to get this params
or try to use this way which uses request action helper
$request = $this->getRequest();
$query = $request->getParam('query');
hope this link will help you
Also you can view all params in a row $this->_request->getParams();
Then find needle param in a row and get using $this->_request->getParam('needle');

Resources