Skip to content
This repository has been archived by the owner on Jan 24, 2018. It is now read-only.

Commit

Permalink
name route and update links
Browse files Browse the repository at this point in the history
  • Loading branch information
cyril.ruedin committed Dec 7, 2016
1 parent 2f56c36 commit f72c3a1
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 19 deletions.
3 changes: 2 additions & 1 deletion app/Http/Controllers/EventController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Illuminate\Http\Request;

use App\Http\Requests;
use Illuminate\Support\Facades\App;

class EventController extends Controller
{
Expand Down Expand Up @@ -47,6 +48,6 @@ public function store(Request $request){
]);

$event->save();
return redirect("en/event/$event->id");
return redirect(route("show_event", ['id' => $event->id, 'lang' => App::getLocale()]));
}
}
2 changes: 1 addition & 1 deletion resources/views/event/creation.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<h3>{{ trans('pages.new_event') }}</h3>

<div class="row">
{!! Form::open(array('url'=>action('EventController@store', App::getLocale()),'class'=>'col s6')) !!}
{!! Form::open(array('url'=>route("store_event", ['id' => $event->id, 'lang' => App::getLocale()]),'class'=>'col s6')) !!}
<div class="row">
<div class="input-field">

Expand Down
2 changes: 1 addition & 1 deletion resources/views/event/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<p>Nothing to bring ! Everything's on the house !</p>
@endforelse
</div>
<a class="btn-floating btn-large waves-effect waves-light red" href="{{url("/en/item/$event->id")}}" id="modifiyItem"><i class="material-icons">add</i></a>
<a class="btn-floating btn-large waves-effect waves-light red" href="{{ route('list_event_items', ['id' => $event->id, 'lang' => App::getLocale()]) }}" id="modifiyItem"><i class="material-icons">add</i></a>

<div id="participants">
@include('event.show_participants',['participants' => $event->participants])
Expand Down
2 changes: 1 addition & 1 deletion resources/views/event/usereventlist.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<img alt="" src="{{asset("/imgs/event_picture_not_found.png")}}">
@endif

<a href="event/{{ $event->id }}" class="collection-item">Go to event</a>
<a href="event/{{ route("show_event", ['id' => $event->id, 'lang' => App::getLocale()]) }}" class="collection-item">Go to event</a>
<p><i class="material-icons">place</i> {{$event->location}}</p>

<p>{{$event->description}}</p>
Expand Down
24 changes: 9 additions & 15 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,30 @@
'middleware' => ['localization']
], function(){

This comment has been minimized.

Copy link
@cyrilruedin

cyrilruedin Dec 12, 2016

Collaborator

@greut

Bonjour

Existe t'il une solution propre permettant d'éviter de mettre la langue avant la route ? Le but est de garder la langue actuelle ou la langue par défaut et ne pas être embêté si on "oublie" de spécifier la langue. Ou envoyer un valeur par défaut au middleware. Un façon de gérer un Prefix vide ?

Une solution serait de copier les routes hors du group, mais je tiens à ma place au paradis

This comment has been minimized.

Copy link
@greut

greut Dec 12, 2016

Member

C'est un choix de conception. La langue peut-être dans l'URL (chemin ou attribut), dans un cookie comme dans la session.

Make sure each language version is easily discoverable

Keep the content for each language on separate URLs. Don’t use cookies to show translated versions of the page. Consider cross-linking each language version of a page. That way, a French user who lands on the German version of your page can get to the right language version with a single click.

Avoid automatic redirection based on the user’s perceived language. These redirections could prevent users (and search engines) from viewing all the versions of your site.

https://support.google.com/webmasters/answer/182192?hl=en

ou, en VF:

Nous utilisons le contenu de la page pour déterminer la langue utilisée, mais l'URL fournit également aux internautes des indices importants. Par exemple, les URL .ca suivantes utilisent fr comme sous-domaine ou sous-répertoire pour indiquer clairement un contenu en français : http://exemple.ca/fr/vélo-de-montagne.html et http://fr.exemple.ca/vélo-de-montagne.html.

Vous pouvez traduire des mots dans vos URL ou bien utiliser un nom de domaine internationalisé (IDN). Veillez à utiliser l'encodage UTF-8 dans vos URL. Nous vous invitons à utiliser cet encodage chaque fois que cela est possible. Pensez également à ajouter des caractères d'échappement dans vos liens.

https://support.google.com/webmasters/answer/182192?hl=fr

Dans le cas où la langue n'est pas spécifié, il faudrat effectuer une redirection basée sur l'entête HTTP: Accept-Language.

En plus du projet de l'année dernière, il y a cette bibliothèque: https://github.com/mcamara/laravel-localization

PS: View::share() c'est pratique 😉

This comment has been minimized.

This comment has been minimized.

Copy link
@grunenwald

grunenwald Dec 12, 2016

Member

Un Route::filter('before', ...) joue aussi en cas d'absence de la langue, ou bien ?
https://bitbucket.org/benjaminrh/gidonim-laravel/src/master/application/routes.php

This comment has been minimized.

Copy link
@greut

greut Dec 12, 2016

Member

Laravel 3.2.8... pas certain que ça le fasse toujours avec le Router actuel.

La seule chose réellement ennuyeuse, à mes yeux, est de ne pouvoir donner une fois pour toute le bon paramètre à route().

Et 🎉 c'est dans Laravel master : laravel/framework#16736

Avec des idées sur un mécanisme plus global.

Pas simple pas simple.

This comment has been minimized.

Copy link
@greut

greut Dec 12, 2016

Member
// List events page
Route::get('event', 'EventController@showEvents');
Route::get('event', ['uses' => 'EventController@showEvents', 'as' => 'list_events']);

Route::get('/', function () {


return view('welcome');
});

// Event page
Route::get('event/{id}', 'EventController@show');
Route::get('create','EventController@showCreationPage');

Route::get('create',['uses' => 'EventController@showCreationPage', 'as' => 'create_event']);


//Pour l'ajout des items

Route::get('item/{id}',['middleware' => 'auth', 'uses' => 'EventItemController@show']);
Route::get('item/{id}',['middleware' => 'auth', 'uses' => 'EventItemController@show', 'as' => 'list_event_items']);

Route::post('item','EventItemController@store');
Route::post('item',['uses' =>'EventItemController@store', 'as' => 'store_item']);


//Creation page

Route::post('event','EventController@store');//Route pour après l'envoie du fomulaire
Route::post('event',['uses' => 'EventController@store', 'as' => 'store_event']);//Route pour après l'envoie du fomulaire


//Add order
Route::post('order','OrderController@userTakes');

Route::get('hello', 'EventController@test');
Route::post('order',['uses' =>'OrderController@userTakes', 'as' => 'store_orders']);

Route::get('event/{id}', ['uses' => 'EventController@show', 'as' => 'show_event']);

});

Expand All @@ -55,7 +49,7 @@
return view('welcome');
});


Route::get('event/{id}', 'EventController@show');
Route::get('login', 'Auth\AuthController@login');
Route::post('login', 'Auth\AuthController@postLogin');
Route::get('auth/token/{token}', 'Auth\AuthController@authenticate');
Expand Down

0 comments on commit f72c3a1

Please sign in to comment.