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

Commit

Permalink
Corrections de commit précédent, terminaison du controlleur des utili…
Browse files Browse the repository at this point in the history
…sateurs, leur modele, leur vues, corrrection du bug des parametres dans le header et les routes
  • Loading branch information
Fábio Marques authored and Fábio Marques committed Dec 13, 2016
1 parent 5936ebd commit 16cb26d
Show file tree
Hide file tree
Showing 12 changed files with 170 additions and 88 deletions.
49 changes: 11 additions & 38 deletions RebelLegion/app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use App\Http\Requests\UserUpdateRequest;

use Illuminate\Pagination\Paginator;
use Illuminate\Support\Facades\View;
use View;

use App;
use App\User;
Expand Down Expand Up @@ -53,13 +53,7 @@ public function create()
*/
public function store(UserCreateRequest $request)
{
$user = new User;
$user->userName = $request->userName;
$user->firstName = $request->firstName;
$user->lastName = $request->lastName;
$user->email = $request->email;
$user->password = $request->password;
$user->save();
$user = User::create($request->only('userName', 'firstName', 'lastName', 'email', 'password'));

This comment has been minimized.

Copy link
@greut

greut Dec 13, 2016

Member

Mieux, non? Un peu de validation par dessus et c'est utlisable.

https://laravel.com/docs/5.3/validation

This comment has been minimized.

Copy link
@fabioman

fabioman Dec 13, 2016

Collaborator

la validation est faite dans App\Http\Requests\UserCreateReques, non?

This comment has been minimized.

Copy link
@greut

greut Dec 13, 2016

Member

Juste, au temps pour moi! J'ai raté la signateur de la méthode courante.

Vive l'injection de dépendances.

This comment has been minimized.

Copy link
@fabioman

fabioman Dec 13, 2016

Collaborator

👍

return redirect()->route('users.index', App::getLocale());
}

Expand All @@ -71,15 +65,8 @@ public function store(UserCreateRequest $request)
*/
public function show($locale, $id)
{
$user = User::find($id);
if (!is_null($user))
{
return View::make('users.show')->with('user', $user);
}
else
{
App::abort(404);
}
$user = User::findOrFail($id);
return View::make('users.show')->with('user', $user);
}

/**
Expand All @@ -88,17 +75,10 @@ public function show($locale, $id)
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
public function edit($locale, $id)
{
$user = User::find($id);
if (!is_null($user))
{
return View::make('users.edit')->with('user', $user);
}
else
{
App::abort(404);
}
$user = User::findOrFail($id);
return View::make('users.edit')->with('user', $user);
}

/**
Expand Down Expand Up @@ -126,17 +106,10 @@ public function update(UserUpdateRequest $request, $id)
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
public function destroy($locale, $id)
{
$user = User::find($id);
if (!is_null($user))
{
$user->delete();
}
else
{
App::abort(404);
}
return redirect()->back();
$user = User::findOrFail($id);
$user->delete();
return redirect()->route('users.index', App::getLocale());
}
}
2 changes: 1 addition & 1 deletion RebelLegion/app/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class User extends Authenticatable
* @var array
*/
protected $fillable = [
'name', 'email', 'password',
'userName', 'firstName', 'lastName', 'email', 'password'
];

/**
Expand Down
6 changes: 0 additions & 6 deletions RebelLegion/public/css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -3576,9 +3576,3 @@ table.hover tbody tr:nth-of-type(even):hover {

.column-1of8 {
width: 12.5%; }

/*# sourceMappingURL=app.css.map */
.error {
background-color: red;
color: white;
}
10 changes: 10 additions & 0 deletions RebelLegion/public/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -614,3 +614,13 @@ font-size: 1.6rem;
0% { top: 60%; }
100% { top: -450%; }
}

.error {
background-color: red;
color: white;
}

.edit_delete_forms{
display: inline-block;
text-align: center;
}
3 changes: 3 additions & 0 deletions RebelLegion/resources/lang/en/forms_buttons_common.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
| Form common Language Lines
|--------------------------------------------------------------------------
*/
'user' => 'User',
'create' => 'Create',
'edit' => 'Edit',
'delete' => 'Delete',
'submit' => 'Submit'
];
3 changes: 3 additions & 0 deletions RebelLegion/resources/lang/fr/forms_buttons_common.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
| Form common Language Lines
|--------------------------------------------------------------------------
*/
'user' => 'Utilisateur',
'create' => 'Créer',
'edit' => 'Éditer',
'delete' => 'Supprimer',
'submit' => 'Soumettre'
];
16 changes: 14 additions & 2 deletions RebelLegion/resources/views/includes/header.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,29 @@
</a>
<ul class="submenu menu vertical is-dropdown-submenu first-sub" >
<li>
@if( isset($user) )
<a tabindex="0" href="{{ route( Route::currentRouteName(), ['lang' => 'fr', 'user' => $user->id]) }}">
@else
<a tabindex="0" href="{{ route( Route::currentRouteName(), ['lang' => 'fr']) }}">
@endif
{{ trans('menus.fr') }}
</a>
</li>
<li>
<a href="{{ route( Route::currentRouteName(), ['lang' => 'de']) }}">
@if( isset($user) )
<a tabindex="0" href="{{ route( Route::currentRouteName(), ['lang' => 'de', 'user' => $user->id]) }}">
@else
<a tabindex="0" href="{{ route( Route::currentRouteName(), ['lang' => 'de']) }}">
@endif
{{ trans('menus.de') }}
</a>
</li>
<li>
<a href="{{ route( Route::currentRouteName(), ['lang' => 'en']) }}">
@if( isset($user) )
<a tabindex="0" href="{{ route( Route::currentRouteName(), ['lang' => 'en', 'user' => $user->id]) }}">
@else
<a tabindex="0" href="{{ route( Route::currentRouteName(), ['lang' => 'en']) }}">
@endif

This comment has been minimized.

Copy link
@greut

greut Dec 13, 2016

Member

!google tabindex

This comment has been minimized.

Copy link
@fabioman

fabioman Dec 13, 2016

Collaborator

je viens de les supprimer

This comment has been minimized.

Copy link
@matbandeli

matbandeli Dec 14, 2016

Member

Pourquoi tu as rajouté le user-id comme paramètre lorsqu'on change de langue?

This comment has been minimized.

Copy link
@fabioman

fabioman Dec 14, 2016

Collaborator

Pour pouvoir changer de langue à tout moment. Si t'es dans la page edit d'un user, par exemple,, tu dois forcément passer l'user id dans la route.

This comment has been minimized.

Copy link
@matbandeli

matbandeli Dec 14, 2016

Member

J'ai trouvé une autre solution qui fonctionne avec toutes les pages, peu importe l'argument.
Tu peux voir dans mon prochain commit

This comment has been minimized.

Copy link
@fabioman

fabioman Dec 14, 2016

Collaborator

C'est quoi la solution?

This comment has been minimized.

Copy link
@matbandeli

matbandeli Dec 14, 2016

Member

J'ai fait un commit sur la branche fixing/frontend.

En gros tu sauvegardes les paramètres de la route actuelle dans une variable de session. et tu récupères ces paramètres quand tu change de langue, dans le fichier web.php

This comment has been minimized.

Copy link
@matbandeli

matbandeli Dec 14, 2016

Member

et la langue je la sauvegarde dans une variable de session car avec App::locale, ça persiste moins bien lorsqu'on navigue sur le site. Je sais pas trop pourquoi.

This comment has been minimized.

Copy link
@greut

greut Dec 14, 2016

Member

La bonne solution est là, mais il faut attendre Laravel 5.4: laravel/framework#16736

{{ trans('menus.en') }}
</a>
</li>
Expand Down
38 changes: 15 additions & 23 deletions RebelLegion/resources/views/users/create.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,76 +2,68 @@

@section('content')

<div class="row">
<div class="large-6 large-centered medium-8 medium-centered small-10 small-centered columns">

{{ Form::open( ['method' => 'POST', 'route' => ['users.store', 'lang' => App::getLocale()]] ) }}
<div class="row">
<div class="large-6 columns">
<h1>@lang('forms_buttons_common.create') @lang('forms_buttons_common.user')</h1>

{{ Form::open( ['method' => 'POST', 'route' => ['users.store', 'lang' => App::getLocale()]] ) }}
<div class="row">
<label for="userName">@lang('users.userName')</label>
<input type="text" id="userName" name="userName" value="{{ old('userName') }}" required autofocus/>
@if ($errors->has('userName'))
<small class="error">{{ $errors->first('userName') }}</small>
@endif
</div>
</div>

<div class="row">
<div class="large-6 columns">
<div class="row">
<label for="firstName">@lang('users.firstName')</label>
<input type="text" id="firstName" name="firstName" value="{{ old('firstName') }}" required/>
@if ($errors->has('firstName'))
<small class="error">{{ $errors->first('firstName') }}</small>
@endif
</div>
</div>

<div class="row">
<div class="large-6 columns">
<div class="row">
<label for="lastName">@lang('users.lastName')</label>
<input type="text" id="lastName" name="lastName" value="{{ old('lastName') }}" required/>
@if ($errors->has('lastName'))
<small class="error">{{ $errors->first('lastName') }}</small>
@endif
</div>
</div>

<div class="row">
<div class="large-6 columns">
<div class="row">
<label for="email">@lang('users.email')</label>
<input type="email" id="email" name="email" value="{{ old('email') }}" required/>
@if ($errors->has('email'))
<small class="error">{{ $errors->first('email') }}</small>
@endif
</div>
</div>

<div class="row">
<div class="large-6 columns">
<div class="row">
<label for="password">@lang('users.password')</label>
<input type="password" id="password" name="password" required/>
@if ($errors->has('password'))
<small class="error">{{ $errors->first('password') }}</small>
@endif
</div>
</div>

<div class="row">
<div class="large-6 columns">
<div class="row">
<label for="passwordConfirmation">@lang('users.passwordConfirmation')</label>
<input type="password" id="passwordConfirmation" name="passwordConfirmation" required />
@if ($errors->has('passwordConfirmation'))
<small class="error">{{ $errors->first('passwordConfirmation') }}</small>
@endif
</div>
</div>

<div class="row">
<div class="large-6 columns">
<div class="row">
<button type="submit" class="button">
@lang('forms_buttons_common.create')
</button>
</div>
</div>

{{ Form::close() }}
{{ Form::close() }}
</div>
</div>

@endsection
70 changes: 70 additions & 0 deletions RebelLegion/resources/views/users/edit.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
@extends('layouts.app')

@section('content')

<div class="row">
<div class="large-6 large-centered medium-8 medium-centered small-10 small-centered columns">

<h1>@lang('forms_buttons_common.edit') @lang('forms_buttons_common.user') : {{ $user->userName }}</h1>


{{ Form::open( ['method' => 'PUT', 'route' => ['users.update', 'lang' => App::getLocale(), 'user' => $user->id]] ) }}

This comment has been minimized.

Copy link
@greut

greut Dec 13, 2016

Member

seuls POST et GET sont acceptés par un navigateur.

https://laravel.com/docs/5.3/controllers#resource-controllers

This comment has been minimized.

Copy link
@fabioman

fabioman Dec 13, 2016

Collaborator

je rajoute {{ method_field('PUT') }} en dessous de l'ouverture du formulaire?
ou je mets tous les formulaires où il y a des données à entrer et suppression d'élements avec POST?

This comment has been minimized.

Copy link
@greut

greut Dec 13, 2016

Member

Il faut croire que Laravel Collective s'en occupe.

Note: Since HTML forms only support POST and GET, PUT and DELETE methods will be spoofed by automatically adding a _method hidden field to your form.

https://laravelcollective.com/docs/5.3/html#opening-a-form

Mais utilisez Form::model()!

This comment has been minimized.

Copy link
@greut

greut Dec 13, 2016

Member

Donc, vous pouvez laisser 'method' => 'put'.

<div class="row">
<label for="userName">@lang('users.userName')</label>
<input type="text" id="userName" name="userName" value="{{ $user->userName }}" required autofocus/>
@if ($errors->has('userName'))
<small class="error">{{ $errors->first('userName') }}</small>
@endif
</div>

<div class="row">
<label for="firstName">@lang('users.firstName')</label>
<input type="text" id="firstName" name="firstName" value="{{ $user->firstName }}" required/>
@if ($errors->has('firstName'))
<small class="error">{{ $errors->first('firstName') }}</small>
@endif
</div>

<div class="row">
<label for="lastName">@lang('users.lastName')</label>
<input type="text" id="lastName" name="lastName" value="{{ $user->lastName }}" required/>
@if ($errors->has('lastName'))
<small class="error">{{ $errors->first('lastName') }}</small>
@endif
</div>

<div class="row">
<label for="email">@lang('users.email')</label>
<input type="email" id="email" name="email" value="{{ $user->email }}" required/>
@if ($errors->has('email'))
<small class="error">{{ $errors->first('email') }}</small>
@endif
</div>

<div class="row">
<label for="password">@lang('users.password')</label>
<input type="password" id="password" name="password" required/>
@if ($errors->has('password'))
<small class="error">{{ $errors->first('password') }}</small>
@endif
</div>

<div class="row">
<label for="passwordConfirmation">@lang('users.passwordConfirmation')</label>
<input type="password" id="passwordConfirmation" name="passwordConfirmation" required />
@if ($errors->has('passwordConfirmation'))
<small class="error">{{ $errors->first('passwordConfirmation') }}</small>
@endif
</div>

<div class="row">
<button type="submit" class="button">
@lang('forms_buttons_common.create')
</button>
</div>

{{ Form::close() }}
</div>
</div>

@endsection
6 changes: 5 additions & 1 deletion RebelLegion/resources/views/users/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

@section('content')

<a href="{{ route('users.create', [ 'lang' => App::getLocale()] ) }}" class="button">@lang('forms_buttons_common.create')</a>
<div class="row">
<div class="large-1 large-centered medium-1 medium-centered small-1 small-centered columns">
<a href="{{ route('users.create', [ 'lang' => App::getLocale()] ) }}" class="button">@lang('forms_buttons_common.create')</a>
</div>
</div>

<div class="first-element row">
<div class="small-centered small-12 large-10 columns game_info_desc">
Expand Down
42 changes: 38 additions & 4 deletions RebelLegion/resources/views/users/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,43 @@

@section('content')

<p>{{ $user->userName }}</p>
<p>{{ $user->firstName }}</p>
<p>{{ $user->lastName }}</p>
<p>{{ $user->email }}</p>
<div class="row">
<div class="large-6 large-centered medium-8 medium-centered small-10 small-centered columns">

<h1>@lang('forms_buttons_common.user') : {{ $user->userName }}</h1>

<table>
<tbody>
<tr>
<th>@lang('users.userName')</th>
<td>{{ $user->userName }}</td>
</tr>
<tr>
<th>@lang('users.firstName')</th>
<td>{{ $user->firstName }}</td>
</tr>
<tr>
<th>@lang('users.lastName')</th>
<td>{{ $user->lastName }}</td>
</tr>
<tr>
<th>@lang('users.email')</th>
<td>{{ $user->email }}</td>
</tr>
</tbody>
</table>

<div class="row">
{{ Form::open([ 'class' => 'edit_delete_forms', 'method' => 'GET', 'route' => ['users.edit', 'lang' => App::getLocale(), 'user' => $user->id] ]) }}
<button type="submit" class="button success">@lang('forms_buttons_common.edit')</button>
{{ Form::close() }}

{{ Form::open([ 'class' => 'edit_delete_forms', 'method' => 'DELETE', 'route' => ['users.destroy', 'lang' => App::getLocale(), 'user' => $user->id] ]) }}
<button type="submit" class="button alert">@lang('forms_buttons_common.delete')</button>
{{ Form::close() }}
</div>

</div>
</div>

@endsection
Loading

0 comments on commit 16cb26d

Please sign in to comment.