Laravel facing issue in Redirecting - laravel

i am working on PTC script where i am facing problem.when i view third page or second page ads then after confirming ad it will automatically redirect back to ads page but i want to redirect it back to the current page(for example if i view second page ad then after confirm it has to redirect to second page)
Here's the code.
UserAdvert Controller.php
session()->flash('message', 'This Ads Has Been Successfully Viewed.');
Session::flash('type', 'success');
Session::flash('title', 'Earn Successful');
return redirect()->route('userCash.links');
}
public function cashLinkShow($id)
{
$advert= Advert::findOrFail($id);
return view('user.viewads.showads', compact('advert'));
}
Route.php
Route::get('user/cash/links', 'UserAdvertsController#cashLinks')->name('userCash.links');
Route::get('user/cash/link/show/{id}', 'UserAdvertsController#cashLinkShow')->name('userCashLinks.show');
Route::get('user/cash/link/confirm/{id}', 'UserAdvertsController#cashLinkConfirm')->name('userCashLink.confirm');
Route::get('user/cash/links?page=links', 'UserAdvertsController#cashLinkPage')->name('userCash.links.page');
Site is redirecting to this address after viewing ads
Route::get('user/cash/links', 'UserAdvertsController#cashLinks')->name('userCash.links');
but i want to redirect back to the current page from where ad is view i created route for this
Route::get('user/cash/links?page', 'UserAdvertsController#cashLinkPage')->name('userCash.links.page');
but i don't know how to get parameter of paginated page.. kindly help me to resolve this issue.I am beginner in laravel thanks

You should try this:
use Redirect;
return Redirect::to('/user/cash/links');

Related

Laravel 9 how to redirect to a custom route after registration in laravel jetstream

I'm using Laravel Jetstream and Laravel 9 for user login and registration. I have also implemented email verification after registration and it works fine.
The problem comes when I want to display a new page called "news" instead of "dashboard" after login and registration. After user login the "news" page is displayed correctly, but after registration of a new users it sends me directly to the news page and not to the email verification page.
How can I show the email verification page when a new user registers and only after he verifies his email, the "news" page appears?
I made this changes to show the news page :
In app/Providers/RouteServiceProviver file changed this line:
public const HOME = '/dashboard';
To this:
public const HOME = '/news';
In the web.php file I added this line to show the route
Route::get('news', [CustomViewController::class, 'showNews'])->middleware('auth')->name('news');
And the showNews function in the controller is:
public function showNews(){
$user = auth()->user()->name;
return view('newviews.news' ,compact('user'));
}
And the view is this:
<x-app-layout>
Welcome {{$user}}
</x-app-layout>
Check the config file of fortify.php what is the value of the equal home,
When the user is authenticated, it will be redirected to that value.

Authentication redirection in codeigniter

I am new to codeigniter framework. I am trying to build a authentication system.
Authentication is working fine. My problem is that after successfully logging, when I click the back button in the browser it is directed to login page again. I want to redirect it to the home page itself. i want to reload the home page not the index page(index page is the login page, after successful login goes to home page)
How can I do it
In your login page check that login session is started or not, if it is started than redirect to home page :
if(isset($_SESSION['user']))
{
header('Location:http://localhost/projectname/home');
}
If you have any confusion please let me inform.
Thanks
on the home page controller check whether the session exists or not. if it exists then redirect to home page otherwise login page.
In your home_model.php do something like below:
<?php
class Home_model extends CI_Model
{
function __construct()
{
parent::__construct();
$this->check_session();
}
function check_session()
{
$session_login = $this->session->userdata("MYLOGIN");
if($session_login == '')
{
redirect('home');
}
if($session_login == 1 && $session_login == TRUE)
{
redirect('home/dashboard');
}
}
}
Load home_model in home controller.

Laravel 4 get previous url on filter

I have form, which the post action will goes to ajax filter (only permit ajax post). If its not ajax, I want the page will be redirected to the submitted form page (previous page). URL::previous just result undefined.
Route::filter('ajax', function() {
if (Request::ajax() === false)
//URL::previous()
});
I use laravel 4.2
I wanted to place a comment but I don't have enough rep.
Did you try the following option?
Redirect::back()->withErrors('error', 'Not a ajax post');
Or without a message
Redirect::back();

Codeigniter Passing parameters from view to controller

view has this anchor:
echo anchor('login', 'Login or Register');
how do i send the current url to my controller login? and then use it on another function called login_validation?
all i want is, login and back to the last url, however nothing works. so i thought saving the current url when i click "Login or Register" and then after login, on function login_validation, i should redirect to that url saved...
controller index
public function index(){
$this->main_login();
}
main_login
public function main_login(){
$this->load->helper('url');
// on view i will call the next function login_validation
$this->load->view("view_login");
}
login_validation
public function login_validation(){
$this->load->library('form_validation');
(...)
if ($this->form_validation->run()){
// i should redirect the saved url here, instead of home
redirect('home');
}else{
(...)
}
}
i appreciate any help
You can do this simply by using $this->agent->referrer() in your controller class main_login().
Save the referrer url into your session, and once the user is validated (or if they are), then you pull that string from session:
in main_login():
// grabs url where you clicked login
$this->session->set_userdata('referrer_url', $this->agent->referrer());
in login_validation():
// pull url from session and redirect, make sure to account for not having url too
redirect( $referrer_url );
I apologize for the delay, i was really busy with the end of the semester,
So i will explain how i did to solve this problem, all i wanted was back to the current page after the login.. so, everytime i open my view login i will save the last page url, with this code:
$refering_url = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '' ;
and then i should save it in my session, so i can access from my controller and redirect the user to the last page, but look, i can’t simple save the url every time i access the view login, beucase every time i miss the password, i will be redirected to the login page, and so the last url, will the login and not the last one, and of course its wrong, So we have to save it on session, but only in the first time we access the view login, to do that, i compare the variable above ($refering_url) to the view login and view login validation, if its not the same, i can confirm that the previous page is the one i was before the login, and then i can save it to my session,
here the comparison, and the last url saved in my session:
if (($refering_url != ‘URL TO VIEW LOGIN‘) &&
($refering_url != ‘URL TO LOGIN VALIDATION){
$this->session->set_userdata('url', $refering_url);
}
after login is validated, on the controller, i should redirect the user , to the last page he was (the url saved on the session), to do that i used this code:
$this->session->set_userdata($data);
$url=$this->session->userdata('url');
redirect($url, 'refresh');

how to use last insert id when redirect same form page in codeigniter

I just try to prevent re submission problem when refresh form page. so I use session flashdata() method and redirect same form page. but I want also display recent inputed data on form VIEW page. then I am try $this->db->insert_id() on my form VIEW page . but it always show 0. how can I solve it?
when you redirect the user after the successful form submission then add the parameter in the url just a exapmle with dummy code to make an idea for you
$insertedid=$this->my_model->add_info();
//your add_info() should return the inserted id
redirect("/myformcontroller/myformpage/".$this->db->insert_id());// add id in redirect url
on your myformcontroller controller's myformpage function
function myformpage() {
$insertedid=$this->url->segment(3);
if(!empty($insertedid)){
//get new added information and pass it to view
}
// your other code
}
hope it makes sense

Resources