Ford555

Ford555

Member Since 5 Months Ago

Experience Points 340
Experience
Level
Lessons Completed 1
Lessons
Completed
Best Reply Awards 0
Best Answer
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • Chatty Cathy Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

06 Jul
4 months ago

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

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

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

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

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!

15 Jun
4 months ago

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

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

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

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

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

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

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

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

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

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

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

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

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

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