Links to forum keeps being truncated - laravel

Please I need help with how my links to the chatter forum are truncated when I click on discussions or any other link on the forum homepage.
A quick solution would be very much appreciated.Kindly Check the URL
Here's an example:
instead of;
localhost/apps/school/forums/discussions
it shows as:
localhost/forums/discussions
Below is the Route/web.php
<?php
/**
* Helpers.
*/
// Route helper.
$route = function ($accessor, $default = '') {
return $this->app->config->get('chatter.routes.'.$accessor, $default);
};
// Middleware helper.
$middleware = function ($accessor, $default = []) {
return $this->app->config->get('chatter.middleware.'.$accessor, $default);
};
// Authentication middleware helper.
$authMiddleware = function ($accessor) use ($middleware) {
return array_unique(
array_merge((array) $middleware($accessor), ['auth'])
);
};
/*
* Chatter routes.
*/
Route::group([
'as' => 'chatter.',
'prefix' => $route('home'),
'middleware' => $middleware('global', 'web'),
'namespace' => 'DevDojo\Chatter\Controllers',
], function () use ($route, $middleware, $authMiddleware) {
// Home view.
Route::get('/', [
'as' => 'home',
'uses' => 'ChatterController#index',
'middleware' => $middleware('home'),
]);
// Single category view.
Route::get($route('category').'/{slug}', [
'as' => 'category.show',
'uses' => 'ChatterController#index',
'middleware' => $middleware('category.show'),
]);
/*
* Auth routes.
*/
// Login view.
Route::get('login', [
'as' => 'login',
'uses' => 'ChatterController#login',
]);
// Register view.
Route::get('register', [
'as' => 'register',
'uses' => 'ChatterController#register',
]);
/*
* Discussion routes.
*/
Route::group([
'as' => 'discussion.',
'prefix' => $route('discussion'),
], function () use ($middleware, $authMiddleware) {
// All discussions view.
Route::get('/', [
'as' => 'index',
'uses' => 'ChatterDiscussionController#index',
'middleware' => $middleware('discussion.index'),
]);
// Create discussion view.
Route::get('create', [
'as' => 'create',
'uses' => 'ChatterDiscussionController#create',
'middleware' => $authMiddleware('discussion.create'),
]);
// Store discussion action.
Route::post('/', [
'as' => 'store',
'uses' => 'ChatterDiscussionController#store',
'middleware' => $authMiddleware('discussion.store'),
]);
// Single discussion view.
Route::get('{category}/{slug}', [
'as' => 'showInCategory',
'uses' => 'ChatterDiscussionController#show',
'middleware' => $middleware('discussion.show'),
]);
// Add user notification to discussion
Route::post('{category}/{slug}/email', [
'as' => 'email',
'uses' => 'ChatterDiscussionController#toggleEmailNotification',
]);
/*
* Specific discussion routes.
*/
Route::group([
'prefix' => '{discussion}',
], function () use ($middleware, $authMiddleware) {
// Single discussion view.
Route::get('/', [
'as' => 'show',
'uses' => 'ChatterDiscussionController#show',
'middleware' => $middleware('discussion.show'),
]);
// Edit discussion view.
Route::get('edit', [
'as' => 'edit',
'uses' => 'ChatterDiscussionController#edit',
'middleware' => $authMiddleware('discussion.edit'),
]);
// Update discussion action.
Route::match(['PUT', 'PATCH'], '/', [
'as' => 'update',
'uses' => 'ChatterDiscussionController#update',
'middleware' => $authMiddleware('discussion.update'),
]);
// Destroy discussion action.
Route::delete('/', [
'as' => 'destroy',
'uses' => 'ChatterDiscussionController#destroy',
'middleware' => $authMiddleware('discussion.destroy'),
]);
});
});
/*
* Post routes.
*/
Route::group([
'as' => 'posts.',
'prefix' => $route('post', 'posts'),
], function () use ($middleware, $authMiddleware) {
// All posts view.
Route::get('/', [
'as' => 'index',
'uses' => 'ChatterPostController#index',
'middleware' => $middleware('post.index'),
]);
// Create post view.
Route::get('create', [
'as' => 'create',
'uses' => 'ChatterPostController#create',
'middleware' => $authMiddleware('post.create'),
]);
// Store post action.
Route::post('/', [
'as' => 'store',
'uses' => 'ChatterPostController#store',
'middleware' => $authMiddleware('post.store'),
]);
/*
* Specific post routes.
*/
Route::group([
'prefix' => '{post}',
], function () use ($middleware, $authMiddleware) {
// Single post view.
Route::get('/', [
'as' => 'show',
'uses' => 'ChatterPostController#show',
'middleware' => $middleware('post.show'),
]);
// Edit post view.
Route::get('edit', [
'as' => 'edit',
'uses' => 'ChatterPostController#edit',
'middleware' => $authMiddleware('post.edit'),
]);
// Update post action.
Route::match(['PUT', 'PATCH'], '/', [
'as' => 'update',
'uses' => 'ChatterPostController#update',
'middleware' => $authMiddleware('post.update'),
]);
// Destroy post action.
Route::delete('/', [
'as' => 'destroy',
'uses' => 'ChatterPostController#destroy',
'middleware' => $authMiddleware('post.destroy'),
]);
});
});
});
/*
* Atom routes
*/
Route::get($route('home').'.atom', [
'as' => 'chatter.atom',
'uses' => 'DevDojo\Chatter\Controllers\ChatterAtomController#index',
'middleware' => $middleware('home'),
]);

You need to set the root directory to point to the public folder in laravel for the url rewriting to work and this won't happen when you're using xampp/wamp and accessing the url like folder structure. Only the index page of laravel app would work and other pages would throw errors. Also the links generated would not be accurate since laravel uses the base app url.
You should run php artisan serve and access your app with http://localhost:8000. This solves your routing and url generating issues. The other option would be to modify the virtual hosts in your local installation which isn't as easy.

Related

How fix redirecting with parameter have error

In my Laravel 5.8 app when there are no data in session I need to redirect to some default control.
I do
return redirect()->route('admin.oauthAdminCallback/' . $form_action);
When in routes/web.php defined :
Route::group(['middleware' => ['auth', 'isVerified', 'CheckUserStatus'], 'prefix' => 'admin', 'as' => 'admin.'], function () {
Route::get('oauthAdminCallback/{form_action}', [ 'uses' => 'Admin\EventsController#oauthAdminCallback']);//->name('oauthAdminCallback');
But I got error :
Route [admin.oauthAdminCallback/calendarActionUpdate] not defined.
If in first line $form_action has value : “calendarActionUpdate”.
Which is correct way ?
MODIFIED :
I tried this way
return redirect()->route('admin.oauthAdminCallback',$form_action);
and this way
return redirect()->route('admin.oauthAdminCallback')->with([
'form_action' => $form_action,
]);
But in both cases I do not have amy error but method was not called!
In my routes/web.php :
Route::group(['middleware' => ['auth', 'isVerified', 'CheckUserStatus'], 'prefix' => 'admin', 'as' => 'admin.'], function () {
Route::get('oauthAdminCallback', [ 'as' => 'oauthAdminCallback', 'uses' =>'Admin\EventsController#oauthAdminCallback']);
// The method below is not called!
public function oauthAdminCallback()
{
session_start();
die("-1 XXZ oauthAdminCallback");
return redirect( is ignored and I can not understand why?
So you're calling the route by its name so
try this
return redirect()->route('admin.oauthAdminCallback',$form_action);
Mention your route as
Route::group(['middleware' => ['auth'], 'prefix' => 'admin', 'as' => 'admin.'], function () {
Route::get('oauthAdminCallback', [ 'as' => 'oauthAdminCallback', 'uses' => 'Admin\EventsController#oauthAdminCallback']);
});
And your callback as below
return redirect()->route('admin.oauthAdminCallback', $form_action);
Tried and tested.

How to add route group inside another route group.. Laravel 5

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
Route::group(['middleware' => 'cors'], function(Router $router){
});
Route::group([
'prefix' => 'api/v1',
'namespace' => 'Api'
], function () {
Route::post('/auth/register', [
'as' => 'auth.register',
'uses' => 'AuthController#register'
]);
Route::post('/auth/login', [
'as' => 'auth.login',
'uses' => 'AuthController#login'
]);
});
I want to add the prefix group route inside the middleware route, how can i achieve that?
You can nest route groups inside of each other. Just wrap one in the closure of the other.
Route::group(['middleware' => 'cors'], function(Router $router){
Route::group(
[
'prefix' => 'api/v1',
'namespace' => 'Api'
], function () {
Route::post('/auth/register', [
'as' => 'auth.register',
'uses' => 'AuthController#register'
]);
Route::post('/auth/login', [
'as' => 'auth.login',
'uses' => 'AuthController#login'
]);
});
});
hey i solved this by,
Route::group([
'prefix' => 'api/v1',
'namespace' => 'Api',
'middleware' =>'cors'
],
function () {
Route::post('/auth/register', [
'as' => 'auth.register',
'uses' => 'AuthController#register'
]);
Route::post('/auth/login', [
'as' => 'auth.login',
'uses' => 'AuthController#login'
]);
});
but the problem here is i am getting this error
XMLHttpRequest cannot load http://localhost:8000/api/v1/auth/login. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:9000' is therefore not allowed access. The response had HTTP status code 500.
is there any problem with my chrome cause i heard there is plugin for cors in chrome.
Thanks :)

laravel 5 create session file works on local but not on live

My application works in local smoothly,but in online live server it always create a new session file in storage/framework/sessions . It shows always token mismatch. I can't find out where is my fault? Actually it works fine in my local server.
My Routes are:
Route::get('/', ['as'=>'dashboardRoute','uses'=>'DashboardController#index']);
//imports
Route::get('import/emails', ['as' => 'importEmailFormRoute', 'uses' => 'ImportController#getEmailImport']);
Route::post('import/emails', ['as' => 'importEmailPostRoute', 'uses' => 'ImportController#postEmailImport']);
Route::get('import/contacts', ['as' => 'importContactFormRoute', 'uses' => 'ImportController#getContactImport']);
Route::post('import/contacts', ['as' => 'importContactPostRoute', 'uses' => 'ImportController#postContactImport']);
//end imports
Route::get('user/profile', 'UserController#profile');
Route::post('user/profile', 'UserController#profileUpdate');
Route::resource('email', 'EmailController');
Route::resource('contacts', 'ContactController');
Route::resource('email-group', 'EmailGroupController');
Route::resource('contact-groups', 'ContactGroupController');
Route::resource('group-data', 'GroupDataController');
Route::resource('contact-group-datas', 'ContactGroupDataController');
Route::resource('user', 'UserController');
Route::resource('mail-log', 'EmailLogController');
Route::resource('sms-log', 'SmsLogController');
Route::get('send-form', 'SendMailController#sendEmailForm');
Route::get('group-mail-form', 'SendMailController#groupMailForm');
Route::post('send', 'SendMailController#sendMail');
Route::post('send-to-group', 'SendMailController#sendMailToGroup');
Route::get('sms/custom-send', ['as' => 'sendCustomSmsFormRoute', 'uses' => 'SmsController#getSendCustomSms']);
Route::post('sms/custom-send', ['as' => 'sendCustomSmsPostRoute', 'uses' => 'SmsController#postSendCustomSms']);
Route::get('sms/send-to-group', ['as' => 'sendGroupSmsFormRoute', 'uses' => 'SmsController#getSendGroupSms']);
Route::post('sms/send-to-group', ['as' => 'sendGroupSmsPostRoute', 'uses' => 'SmsController#postSendGroupSms']);
// api
Route::group(['prefix' => 'api'], function () {
Route::get('email', ['as' => 'tagEmailListRoute', 'uses' => 'ApiController#tagEmailList']);
Route::get('contact', ['as' => 'tagContactListRoute', 'uses' => 'ApiController#getTagContactList']);
Route::group(['prefix' => 'data-table'], function () {
Route::get('emails', ['as' => 'emailListDataTableRoute', 'uses' => 'ApiController#emailListDataTable']);
});
});
//end api
Route::controllers([
'auth' => 'Auth\AuthController',
'password' => 'Auth\PasswordController',
]);
My session config:
'driver' => env('SESSION_DRIVER', 'file'),
'lifetime' => 120,
'expire_on_close' => false,

Laravel route is forcing me to use a /doube/route and not /single

I've having a weird issue than I don't fully understand...
Here is my route:
Route::get('/app/signin', array( 'as' => 'account-login', 'uses' => 'AccountController#getLogin' ));
Which works great. However, when I loose the /app part I get an error. If I change it to
Route::get('/signin', array( 'as' => 'account-login', 'uses' => 'AccountController#getLogin' ));
I get the following error:
* #throws \Symfony\Component\HttpKernel\Exception\HttpException
* #throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
*/
public function abort($code, $message = '', array $headers = array())
{
if ($code == 404)
{
throw new NotFoundHttpException($message);
}
else
Any help would be greatly appreciated
** UPDATE 1 **
Here is my full list of routes:
// ALL PUBLIC ACCESS ROUTES
Route::get('/', array( 'as' => 'home', 'uses' => 'HomeController#home' ));
Route::get('/{username}', array( 'as' => 'profile-user', 'uses' => 'ProfileController#user' ));
// UNAUTHENTICATED GROUP (GUEST - PUBLIC ACCESS WITH FORMS AND SIGNUP)
Route::group(array('before' => 'csrf'), function() {
Route::post('/app/create', array( 'as' => 'account-create-post', 'uses' => 'AccountController#postCreate' ));
Route::post('/app/login', array( 'as' => 'account-login-post', 'uses' => 'AccountController#postLogin' ));
Route::post('/app/forgot-password', array( 'as' => 'account-forgot-password-post', 'uses' => 'AccountController#postForgotPassword' ));
});
Route::get('/app/forgot-password', array( 'as' => 'account-forgot-password', 'uses' => 'AccountController#getForgotPassword' ));
Route::get('/app/recover{code}', array( 'as' => 'account-recover', 'uses' => 'AccountController#getRecover' ));
Route::get('/app/signin', array( 'as' => 'account-login', 'uses' => 'AccountController#getLogin' ));
Route::get('/app/create', array( 'as' => 'account-create', 'uses' => 'AccountController#getCreate' ));
Route::get('/app/activate/{code}', array( 'as' => 'account-activate', 'uses' => 'AccountController#getActivate' ));
// AUTHENTICATED GROUP (WHEN USER IS LOGGED IN)
Route::group(array('prefix' => 'app', 'before' => 'auth'), function() {
Route::group(array('before' => 'csrf'), function() {
Route::post('/change-password', array( 'as' => 'account-change-password-post', 'uses' => 'AccountController#postChangePassword' ));
});
Route::get('/change-password', array( 'as' => 'account-change-password', 'uses' => 'AccountController#getChangePassword' ));
Route::get('/signout', array( 'as' => 'account-sign-out', 'uses' => 'AccountController#getSignOut' ));
});
Route::get('/{username}', array( 'as' => 'profile-user', 'uses' => 'ProfileController#user' ));
Is the problem, I would suggest to clarify this route with prepending something to it, or put it to the bottom of the routes, so other defined one-word routes get catched first with their respective controllers.
It is also advisable to insert a regular expression (modify to suit your needs)
Route::pattern('username', '[a-z]+')
before that route or use where clause like this
Roue::get( /* username */ )->where('username', '[a-z]+');
This approach should be used on every route parameter, for more control over the Routes and data manipulation.
Side note
Prevent users to have usernames with other one-word routes you have, because they will not be accessible, as user #BarryWalsh suggested.
That does seem strange, but as a start I'd try seeing if removing the preceeding slashes from the target URI (so '/signin' becomes 'signin') fixes the issue as these aren't necessary.

Routing Remap Laravel 4

I'm using Laravel 4, I'm trying to create a cms pages which the urls look like : domain.tld/en/how-it-works. they are created using a backoffice and I fetch it using the slug how-it-works and the current language . The problem is that if I want to access to domain.tld/login (which is a static page) it shows me a 404 page, of course because the page is not found in the database. So I'm looking for a solution which looks in the other routes if the given slug is not found.
Please any help.
And sorry for my english.
This my routes.php file
$languages = array('fr', 'en');
$locale = Request::segment(1);
if(in_array($locale, $languages)){
\App::setLocale($locale);
}else{
$locale = null;
}
Route::group(array('prefix' => $locale), function()
{
Route::get('/', array('before' => 'loginCookie', 'uses' => 'HomeController#getIndex', 'as' => '/'));
Route::get('{slug}',array('uses' => 'ArticleController#getArticle', 'as' => 'articles.show'));
Route::group(array('prefix' => 'login'), function() {
Route::get('/', array('before' => 'guest', 'after' => 'reflashPool', 'uses' => 'UserController#getLogin'));
Route::post('/',array('before' => 'guest|csrf','after' => 'reflashPool', 'uses' => 'UserController#postLogin'));
Route::get('remind-password',array('uses' => 'UserController#getRemind'));
Route::post('remind-password','UserController#postRemind');
Route::get('reset-password/{token}','UserController#getReset');
Route::post('reset-password','UserController#postReset');
});
To be as fast as possible, Laravel process routes in the order you write them and the first one which met the requirement is the one it choses.
So, you just have to make your most generic route the last one:
Route::group(array('prefix' => $locale), function()
{
Route::get('/', array('before' => 'loginCookie', 'uses' => 'HomeController#getIndex', 'as' => '/'));
Route::group(array('prefix' => 'login'), function() {
Route::get('/', array('before' => 'guest', 'after' => 'reflashPool', 'uses' => 'UserController#getLogin'));
Route::post('/',array('before' => 'guest|csrf','after' => 'reflashPool', 'uses' => 'UserController#postLogin'));
Route::get('remind-password',array('uses' => 'UserController#getRemind'));
Route::post('remind-password','UserController#postRemind');
Route::get('reset-password/{token}','UserController#getReset');
Route::post('reset-password','UserController#postReset');
});
Route::get('{slug}',array('uses' => 'ArticleController#getArticle', 'as' => 'articles.show'));
});

Resources