Laravel direct to index page having username - laravel

I want to redirect to index page having username or other things. Like a branch coordinator when do login , then he redirect to index/{branch_name}.
Please help me to do that.
My Route :
Route::get('/branch' , 'HomeController#index');
Controller :
class HomeController extends Controller
{
public function __construct()
{
$this->middleware('auth:branch');
}
public function index()
{
return view('branch.index');
}
}

In web.php change to :
Route::get('/branch/{branch_name}' , 'HomeController#index');
In controller
public function index($branch_name)
{
//$branch_name will be containg the variable
return view('branch.index');
}
To redirect to above page
return redirect()->route('branch/'.$branch_name);

Related

Laravel Resource Routing not showing anything when directly call method

I am stuck in resource routing
when I enter url netbilling.test/customer it goes to customer index file but when I enter url netbilling.test/customer/index nothing is returned. Also guide me if I have to route different method than in resource what is the method for that.
here is my web.php,
Route::get('/dashboard', function () {
return view('dashboard/index');
});
Route::resource('/customer','CustomerController');
here is my customer controller :
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Customer;
use App\Package;
use Redirect,Response;
class CustomerController extends Controller
{
public function index()
{
$packages = Package::get();
$customers = Customer::orderBy('id', 'DESC')->get();
return view('customer/index', compact('customers','packages'));
}
public function create()
{
//
}
public function store(Request $request)
{
//
}
public function show($id)
{
//
}
public function edit($id)
{
//
}
public function update(Request $request, $id)
{
//
}
public function destroy($id)
{
}
}
Without custom route specification, this is how the index route maps to a Resource Controller, taken from Actions Handled By Resource Controller:
Verb
URI
Action
Route Name
GET
/photos
index
photos.index
So if you want URI /customer/index to work, then you need to specify this explicitly in your Controller:
use App\Http\Controllers\CustomerController;
Route::resource('customer', CustomerController::class);
Route::get('customer/index', [CustomerController::class, 'index'])->name(customer.index);

How to get route parameter on difference function on laravel?

I have a problem in my project laravel, I want to get route parameter 'id_project' on route 'project' to use in route 'modulproject'. This route in one view.
This is my Route:
Route::get('project/{id_project}','ProjectDetailController#project');
Route::get('modulproject','ProjectDetailController#modulproject');
This is my Controller:
public function project($id_project)
{
$project=Project::where('id','=',$id_project);
return($project);
}
public function modulproject($id_project)
{
$modulproject=Modul::where('id_project','=',$id_project);
return($modulproject);
}
You can used Session to get that id_project.
use Session;
public function project($id_project)
{
Session::put('id_project',$id_project);
$project=Project::where('id','=',$id_project);
return($project);
}
public function modulproject()
{
if(Session::has('id_project')){
$modulproject=Modul::where('id_project','=',Session::get('id_project'));
Session::forget('id_project');
return($modulproject);
}
else{
return 'redirect to other page.. (custom)';
}
}

URL change issue after form post in Codeigniter

how can i manage url in address bar after posting a form or after loading a page after submission.
Is it possible to manage with routing ?
<?php
public function index(){
$this->load->view('login');
}
public function login_process(){
....... code......
if($login==true){
$this->load->view('dashboard'); // Url is not changing but view is loaded
}else{
$this->load->view('login');
}
}
?>
Hope this will help you :
Use redirect() method from url helper , make sure you load it in controller or in autoload.php
public function login_process()
{
....... code......
if($login === TRUE)
{
redirect('controller_name/dashboard','refresh');
/*$this->load->view('dashboard'); */
}
else
{
redirect('controller_name/index','refresh');
/*$this->load->view('login');*/
}
}
For more :https://www.codeigniter.com/user_guide/helpers/url_helper.html#redirect
You should create another method called dashboard and you should redirect to it like following
class Example_Controller extends CI_Controller {
public function index(){
$this->load->view('login');
}
public function dashboard(){
$this->load->view('dashboard');
}
public function login_process(){
// Your Code
redirect('Example_Controller/' . (($login==true) ? 'dashboard' : 'index'));
}
}
replace Example_Controller with your controller name.
and add following lines in routes.php
$route['login'] = 'Example_Controller/index';
$route['dashboard'] = 'Example_Controller/dashboard';

Lravel 5.2 session::forget() and session::flush() not working

i have just make a sub authentication Middleware in my Laravel 5.2 application which use Laravel session to store data.
I can put my data to Laravel session
But when i want to delete that variable form session it working for only that request when page redirect or someone reload the page that variable still exists.
In My controller File
class SubmissionController extends Controller
{
public function login(Request $request){
if($request->session()->has('submission')) return redirect('/submission-directory');
return view('submission.login');
}
public function dologin(Request $request){
if(!$request->get('password') == "reader") return redirect('/submission-directory/login')->withErrors('errors.wrong-password');
Session::put('submission','yes');
$redirect = $request->session()->pull('submission_redirect','/submission-directory');
return redirect($redirect);
}
public function index(Request $request){
dump($request->session()->all());
$request->session()->forget('submission');
dump($request->session()->all());
die('coming here');
}
}
but when I reload the page You can session is still exists..
Notice :: I have put all the routs in web Middleware group
Route.php
Route::group(['middleware' => 'web'], function () {
Route::group(['prefix'=>'/submission-directory'],function(){
Route::get('/login','submissionController#login');
Route::post('/login',['as'=>'submission.login','uses'=>'SubmissionController#doLogin']);
Route::group(['middleware'=>'submission'],function(){
Route::get('/','SubmissionController#index');
});
});
Try this
IN Controller :
use Session;
public function index(Request $request)
{
dump(Session::all());
Session::forget('submission');
print_r((Session::all());
die;
}

Controller method not found Laravel 4

I have only this route in routes.php
Route::controller('/', 'HomeController');
and this is the HomeController.php
class HomeController extends \BaseController {
public function getAboutUs()
{
return "About page";
}
public function getIndex()
{
return "Home page";
}
}
the '/' page is OK but when I try to go /about-us page it returns "controller method not found"
You should add a about-us route in your routes.php
Route::get('about-us', 'HomeController#getAboutUs');

Resources