Skip to content

Instantly share code, notes, and snippets.

@platinize
Created March 15, 2018 12:49
Show Gist options
  • Save platinize/4c9dff4a7400cd7d2b0c7fbaf7be7739 to your computer and use it in GitHub Desktop.
Save platinize/4c9dff4a7400cd7d2b0c7fbaf7be7739 to your computer and use it in GitHub Desktop.
Laravel_1
<form action="form" method="POST" enctype="multipart/form-data">
@foreach ($arr as $key => $val)
@if($key=='comment')
<p><textarea rows="5" cols="35" name="{{$key}}"></textarea>{{$val}}</p>
@elseif($key=='movieGenres')
<p>@foreach($val as $movieKey=>$value)
<label><input type="checkbox" name="{{$key}}[]" value="{{$movieKey}}">{{$value}}</label>
@endforeach</p>
@elseif($key=='sex')
<p>@foreach($val as $sexKey=>$sexVal)
<label><input type="radio" name="{{$key}}" value="{{$sexKey}}">{{$sexVal}}</label>
@endforeach</p>
@elseif($key=='daysOfTheWeek')
<p><label><select name="{{$key}}">
@foreach($val as $dayKey=>$deyVal)
<option value="{{$dayKey}}">{{$deyVal}}</option>
@endforeach
</select>Выберите день недели</label></p>
@elseif($key=='img')
<p><label><input type="file" name="{{$key}}">Загрузите фото</label></p>
@else
<p><label><input type="text" name="{{$key}}">{{$val}}</label></p>
@endif
@endforeach
<p><input type="submit" name="send"></p>
{{ csrf_field() }}
</form>
@if ($errors->any())
<div class="alert alert-danger">
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
<head>
<style>
div {float:left;margin: 20px;}
p {margin: 0 0 8px}
.fullName {font-size: 20px; font-weight: 600}
</style>
</head>
<h1>Profile</h1>
<div>
<img src="../storage/app/{{$img}}" style="max-width: 300px;">
</div>
<div>
@foreach($arr as $key=>$val)
@if($key == 'movieGenres')
<p class="{{$key}}">Любимые жанры фильмов:
@foreach($val as $num)
@if ($loop->last)
{{$column['movieGenres'][$num]}}.
@else
{{$column['movieGenres'][$num]}},
@endif
@endforeach</p>
@elseif ($key == 'sex')
<p class="{{$key}}">Пол: {{$column['sex'][$val]}}</p>
@elseif($key == 'daysOfTheWeek')
<p class="{{$key}}">День недели : {{$column['daysOfTheWeek'][$val]}}</p>
@else
<p class="{{$key}}">{{$column[$key]}} : {{$val}}</p>
@endif
@endforeach
</div>
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class UserController extends Controller
{
private $column = [
'fullName'=>'ФИО',
'email'=>'email',
'phone'=>'Телефон',
'numCard'=>'Номер карты',
'comment'=>'Комментарий',
'movieGenres'=>['1'=>'Комедии','Боевики','Военные','Драмы','Триллеры','Исторические','Документальные','Ужасы' ],
'sex'=>['1'=>'Мужской', '2'=>'Женский'],
'daysOfTheWeek'=>['Выберите день','Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб', 'Вс'],
'img'=>'Фото' ];
public function createForm(Request $request) {
if ($request->method() == 'POST') {
$this->validate($request, [
'fullName' => 'required|max:100',
'email' => 'email|required',
'phone' => 'required|regex:/(0)[0-9]{9}/',
'numCard' => 'max:16',
'comment' => 'required|max:600',
'movieGenres' => 'required',
'sex' => 'required|in:1,2',
'daysOfTheWeek' => 'required',
'img' => 'required|image',
],
['fullName.required'=>'не должно быть пустым'],
['email.required'=>'не должно быть пустым'],
['phone.required'=>'не должно быть пустым']);
$img = $request->img->store('images');
$arr = $request->all();
unset($arr['_token'], $arr['send'], $arr['img']);
return view('profile',['arr' => $arr, 'img'=>$img, 'column'=>$this->column]);
}
return view('form', ['arr'=>$this->column]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment