laravel 4 page is not working for a newbie - laravel-4

I am totally new for laravel and trying to create a view for about us page.
But it is not working right when I am setting this in a route file.
Here is my HomeController functions:
public function showWelcome()
{
return View::make('hello');
}
public function showAboutus()
{
return View::make('about.about');
}
And here is the routes file:
Route::get('/', 'HomeController#showWelcome');
Route::get('about', 'HomeController#showWelcome');

.... 'HomeController#showWelcome' ...
should be
.... 'HomeController#showAboutus' ...
On the About route.
Plus the second parameter is an array so use
Route::get('/', array('uses' => 'HomeController#showWelcome'));
Route::get('about', array('uses' => 'HomeController#showAboutus'));

Related

Return to resource route

I have below route in my route file.
Route::group( ['prefix' => 'prayer', 'as' => 'prayer.'], function () {
Route::resource( 'time', 'PrayerTimeController' );
});
How can I return to this route from Controller ?
Firstly, I highly recommend reading through the excellent Laravel documentation: https://laravel.com/docs/9.x/controllers#resource-controllers
To get the route wired up to a controller, update your route resource declaration to use the full class name of the controller:
Route::resource('time', PrayerTimeController::class);
Create a controller file: App\Http\Controllers\PrayerTimeController.php with this content:
<?php
namespace App\Http\Controllers;
class PrayerTimeController extends Controller
{
public function index()
{
return 'Hello, World!';
}
}
Then import the controller namespace into the routes file you're working in, e.g. routes/web.php file:
use App\Http\Controllers\PrayerTimeController;
Route::group(['prefix' => 'prayer', 'as' => 'prayer.'], function () {
Route::resource('time', PrayerTimeController::class);
});

Laravel except a single route from auth middleware

I have a route group which is protected by the auth middleware, and inside of this group I want to except one route. But this route is also located in another route group. So when I try to move it out of this group, it is not working.
How can I fix this problem, and except a UrlProfile function from auth middleware?.. I am using Laravel 5.1
Route::group(['middleware' => 'auth'], function () {
// some other routes ...
Route::group(['namespace' => 'Lawyer'], function() {
Route::get('profile/{name}', 'ProfileController#UrlProfile');
}
};
Can you try this?
Route::group(['namespace' => 'Lawyer'], function () {
Route::get('profile/{name}', 'ProfileController#UrlProfile');
Route::group(['middleware' => 'auth'], function() {
..
..
..
)};
)};
If I understood your problem correctly, This should also work.
You can add this in your controller.
You can insert the name of your function in the except section and it will be excluded from the middleware. [Reference]
public function __construct()
{
$this->middleware('auth')->except(['yourFunctionName']);
}

Laravel : How to define route start with prefix # like medium.com/#{username}?

How to define route in laravel , which start with prefix # in web.php
like myapp.com/#username
use route group() to define prefix as -
Route::group(['prefix' => '#username'], function () {
Route::get('/','TestController#test');
});
You can access this url as www.base_url.com/#username/
If you want to set username dynamically then you could this-
Route::group(['prefix' => '#{username}'], function () {
Route::get('/','TestController#test');
});
And in your controller-
public function test($username)
{
echo $username;
}
I have got my answer .
Route::group(['namespace' => 'User','prefix' => '#{username}'],
function () {
Route::get('/','UserController#get_user_profile');
});
in User Controller
public function get_user_profile($username){
$user=User::where('slug',$username)->first();
return response()->json($user);
}

Laravel redirect route with a parameter from controller

I'm trying to redirect a route from a controller function after a form submit process in Laravel 5.4 as it is said in link below
https://laravel.com/docs/5.4/redirects#redirecting-named-routes
Route;
Route::group(['middleware' => ['api'], 'prefix' => 'api'], function () {
Route::post('doSomething', 'Page#doSomething');
});
Route::post('/profile', function () {
//..
});
Controller;
public function doSomething(Request $request){
return redirect()->route('profile', ['id'=>1]);
}
When I try to redirect I get this error.
InvalidArgumentException in UrlGenerator.php line 304: Route [profile]
not defined.
I have searched several times about redirection but I got similar results.
Any suggestions ? Thank you.
route() works with named routes, so name your route
Route::post('/profile', function () {
//..
})->name('profile');

How admin route in laravel 4

My folder structure is following:
Controller>admin>`loginController`
view>admin
model>admin
In LoginController includes authorization process
I have used routes:
Route::group(['prefix' => 'admin'], function() {
Route::get('/', 'LoginController');
});
But i also found error 'Controller method not found.
You either have to use Route::controller() or specify the action that you want to route to. For example:
Controller
public function showLogin(){
return View::make('login');
}
Route
Route::get('/', 'LoginController#showLogin');
(With the # part you tell Laravel what controller method you want to call)

Resources