Ford555

Experience

340

0 Best Reply Awards

  • Member Since 3 Months Ago
  • 1 Lesson Completed
  • 0 Favorites

6th July, 2018

Ford555 left a reply on I Need To Redirect For Several Domains From Http://www. To Http://. In Laravel5.6 App • 2 months ago

Thanks! Yes plesk has a place for put text for nginx and i Think i got it. It was a pleasure! Thanks

Ford555 left a reply on I Need To Redirect For Several Domains From Http://www. To Http://. In Laravel5.6 App • 2 months ago

ok i always used apache before (for 10 years) and now this is my first time i use nginx because i thought laravel is implemented with nginx.

For homestead your explanation is very helpfull!! i am going to implement this now, but then how i can do it in production? do you know how to do it? i use plesk

thanks a lot and sorry about my english

Ford555 left a reply on I Need To Redirect For Several Domains From Http://www. To Http://. In Laravel5.6 App • 2 months ago

thank for the response. I am going to use nginx in plesk (i am finishing my website). In local i have homestead. i used somehitng like this ' RewriteCond %{HTTPS} on

RewriteCond %{HTTP_HOST} ^www.(.*)$ [NC]

RewriteRule ^(.*)$ https://%1/$1 [R=301,L] '

Ford555 started a new conversation I Need To Redirect For Several Domains From Http://www. To Http://. In Laravel5.6 App • 2 months ago

Hello,

i have 3 domains example.es , example.cat and example.com whith same code. And i need for seo quit the alias www (redirect it without www)

example http://www.example.com to http://example.com and the same with the others.

¿whats the best for do it in laravel5.6 application?

  1. .htaccess??? i tried something but it doesnt works 2)middleware??? how?

can someone put the code i need, thank you!

15th June, 2018

Ford555 left a reply on Laravel5.6 Best Way For Variable Environment With Two Domains • 3 months ago

ok my final code working!!

/app/Providers/RouteServiceProvider.php:

protected function mapWebRoutes()
    {
        $value1 = 'example1.com';
        $value2 ='example2.com';

        $url = \Request::server('HTTP_HOST');//i need this way

        $check1 = str_contains($url, $value1);
        $check2 = str_contains($url, $value2);

        if($check1 == true){

            \App::setLocale('es');
            $routes_file = 'routes/web.es.php';
            config(['delegation.delegation_id' => 1]);
        } else {
                \App::setLocale('en');
                $routes_file = 'routes/web.en.php';
        config(['delegation.delegation_id' => 2]);

        Route::middleware('web')
        ->namespace($this->namespace)
        ->group(base_path($routes_file));
    }

no more middleware CustomDommain.php, i deleteed it

my web.es.php is:

Route::get('/', '[email protected]');
Route::get('/contacto.html', '[email protected]');
//more routes here

my web.en.php is:

Route::get('/', '[email protected]');
Route::get('/contact.html', '[email protected]');
//more routes in english here

my config/delegation.php

<?php

return [
    'delegation_id' => '1'
];

in all controllers works fine getting delegation_id variable!!! for example

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class WelcomeController extends Controller
{
    public function index() {
        $value = config('delegation.delegation_id');
        return view('welcome',  compact('value '));
    }
}

And thats it!!! i get the locale, de delegation_id and all is working perfectly. Hope it can helps other. thanks!!!

Ford555 left a reply on Laravel5.6 Best Way For Variable Environment With Two Domains • 3 months ago

ok thank you! i am going to use provider and y will quit middleware and thats it all!

I am very grateful to both of you, thanks!

Ford555 left a reply on Laravel5.6 Best Way For Variable Environment With Two Domains • 3 months ago

i think the same, i will wait for 36864 response or if not your solution of use only web.php with the conditional in it works well for me also. So we will wait best way to do it hehe. thanks

Ford555 left a reply on Laravel5.6 Best Way For Variable Environment With Two Domains • 3 months ago

ok my final code, hope it helps others.

/app/Providers/RouteServiceProvider.php:

protected function mapWebRoutes()
    {
        switch( config('delegation.delegation_id') ) {
            case 1: $routes_file = 'routes/web.es.php';
            break;
            default: $routes_file = 'routes/web.en.php';
            break;
        }
        Route::middleware('web')
        ->namespace($this->namespace)
        ->group(base_path($routes_file));
    }

but it always take default value on switch ¿? , config('delegation.delegation_id') is null i think but i dont know why¿?

my middleware CustomDommain.php:

<?php

namespace App\Http\Middleware;

use Closure;

class CustomDomain
{
/**
* Handle an incoming request.
*
* @param  \Illuminate\Http\Request  $request
* @param  \Closure  $next
* @return mixed
*/
public function handle($request, Closure $next)
{

    $value1 = 'example1.com';
    $value2 ='example2.com';


    $url = $request->getHost();

    $check1 = str_contains($url, $value1);
    $check2 = str_contains($url, $value2);

    if($check1 == true){
//SPANISH DOMAIN
        \App::setLocale('es');
        config(['delegation.delegation_id' => 1]);
    } else {
//ENGLISH DOMAIN
        \App::setLocale('es');
        config(['delegation.delegation_id' => 2]);
    }

    return $next($request);
}
}

note: watch the '' before App::setLocale('es');

file kernel.php in array protected $middleware i add the line:

\App\Http\Middleware\CustomDomain::class,

I dont know if it is ok!! put it on protected $middleware varibale¿??¿?. I need it ian all urls of course so i guest yes.

my web.es.php is:

Route::get('/', '[email protected]');
Route::get('/contacto.html', '[email protected]');
//more routes here

my web.en.php is:

Route::get('/', '[email protected]');
Route::get('/contact.html', '[email protected]');
//more routes in english here

my config/delegation.php

<?php

return [
    'delegation_id' => '1'
];

in all controllers works fine getting delegation_id variable

$value = config('delegation.delegation_id');
        dd($value);

I am almost finishing :), thanks in advance!

Ford555 left a reply on Laravel5.6 Best Way For Variable Environment With Two Domains • 3 months ago

Ok I understand! so i can see it clearly. Ok i am going to implement. thank you very much grenadecx and 36864

Ford555 left a reply on Laravel5.6 Best Way For Variable Environment With Two Domains • 3 months ago

hello 36864, do you meanchange /app/Providers/RouteServiceProvider.php? where i put the if sentece? here? if you could explain more i would be very glad, thank you!

/**
     * Define the "web" routes for the application.
     *
     * These routes all receive session state, CSRF protection, etc.
     *
     * @return void
     */
    protected function mapWebRoutes()
    {
        Route::middleware('web')
             ->namespace($this->namespace)
             ->group(base_path('routes/web.php'));
    }

Ford555 left a reply on Laravel5.6 Best Way For Variable Environment With Two Domains • 3 months ago

thank you very much grenadecx. in minutes i am going to write my final code, so it could help others!

Ford555 left a reply on Laravel5.6 Best Way For Variable Environment With Two Domains • 3 months ago

maybe it could be

if(config(delegation.delegation_id) === 1){
} else {
}

what doy you think?

Ford555 left a reply on Laravel5.6 Best Way For Variable Environment With Two Domains • 3 months ago

thank you!. Yes i replace it, is cleaner. One thing i forgot. domain in english must be with urls in english. I mean routes are same controllers but not equal uri. For instance, for example1.com i need

 Route::get('/contacto.html', '[email protected]');

and for example2.com it would be ´´´php Route::get('/contact.html', '[email protected]'); ´´´ how i can write it? i mean the if sentence in web.php. Hope i makes me understand

Ford555 left a reply on Laravel5.6 Best Way For Variable Environment With Two Domains • 3 months ago

You are right!. in the other hand i write this '''php $value1 ='example1.com'; $value2 = 'example2.com';

$url = Request::server('HTTP_HOST');

$check1 = str_contains($url, $value1);
$check2 = str_contains($url, $value2);

''' beacuse i have for local example1.com-pre example2.com.pre

and for production it will be example1.com example2.com

so, the code is the same for development and for production.

Ford555 left a reply on Laravel5.6 Best Way For Variable Environment With Two Domains • 3 months ago

wow, so fast answer!. I am going to read it and to implement in my project and i answered later. thanks in advance!!

Ford555 left a reply on Laravel5.6 Best Way For Variable Environment With Two Domains • 3 months ago

sorry i put < c o d e > < / c o d e > but it is not showing well the code :(

Ford555 started a new conversation Laravel5.6 Best Way For Variable Environment With Two Domains • 3 months ago

Hello all, first sorry about my english. second i am new on laravel, i come from codeigniter and i dont know exactly how to do it. I use to read and i never ask in forum, this is my first post because i did not found the exact answer for me. situation: I have 2 domain www.example1.com and www.example2.com. I have same code for the two domains. What i want is set global variables environment according with the domain and change language because one domain is in one language and the other is in other. i thought this code but i dont know best way to do this. Please, can you help me?

I am using for this my file web.php Route::group(array('domain' => Request::server('HTTP_HOST')), function() {

$value1 ='example1.com';
$value2 = 'example2.com';

$url = Request::server('HTTP_HOST');

$check1 = str_contains($url, $value1);
$check2 = str_contains($url, $value2);

if($check1 == true){

    //here i write all that i need for example1.com (all my globals environment)
    App::setLocale('es');
    config(['delegation.delegation_id' => 1]);
    
    Route::get('/', '[email protected]');
    
}
if($check2 == true){

    App::setLocale('en');
    config(['delegation.delegation_id' => 2]);
    
    //here i write all that i need for example2.com (all my globals environment)
    Route::get('/', '[email protected]');
    
}

});

then in WelcomeController.php or in the other controllers it works

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.