Commit 0be9f75d authored by gop20's avatar gop20
Browse files

adicionado validacao

parent 59303371
No related merge requests found
Showing with 34 additions and 24 deletions
+34 -24
......@@ -15,24 +15,29 @@ class GalleryController extends Controller
public function index()
{
$search = request()->query('search');
if($search){ // testa se ha um request de search
if ($search) { // testa se ha um request de search
$images = Image::where('title', 'LIKE', '%' . $search . '%')->orderBy('year', 'desc')->paginate(4);
}
else{
} else {
$images = Image::orderBy('year', 'desc')->paginate(4);
}
}
$imageYears = ImageYears::orderBy('year', 'desc')->get();
return view('dashboard.galeria.index')->with(['images' => $images, 'imageYears' => $imageYears, 'search' => $search]);
}
public function create()
{
return view('dashboard.galeria.create');
}
public function store(ImageRequest $request)
{
$request->validate([
'year' => 'required|integer|min:0|max:2022',
'title' => 'required|unique:images',
'description' => 'required'
]);
$year = $request['year'];
if (empty(DB::table('image_years')->where('year', '=', $year)->first())) {
// caso nao tenha nenhuma entrada na table image_years com o ano especificado, cria uma
......@@ -56,31 +61,37 @@ class GalleryController extends Controller
return redirect('dashboard/galeria');
}
public function show($id)
{
$image = Image::findOrFail($id);
return view('dashboard.galeria.show')->with(['image' => $image]);
}
public function edit($id)
{
$image = Image::findOrFail($id);
return view('dashboard.galeria.edit')->with(['image' => $image]);
}
public function update(UpdateImageRequest $request, $id)
{
$image = Image::findOrFail($id);
$request->validate([
'year' => 'required|integer|min:0|max:2022',
'title' => 'required|unique:images',
'description' => 'required'
]);
$year = $request['year'];
$image->title = $request->title;
$image->description = $request->description;
$image->year = $year;
if (empty(DB::table('image_years')->where('year', '=', $year)->first())) {
// caso nao tenha nenhuma entrada na table image_years com o ano especificado, cria uma
$imageYears = ImageYears::create([
......@@ -91,10 +102,10 @@ class GalleryController extends Controller
}
$image->update();
return redirect('dashboard/galeria');
}
public function destroy($id)
{
$image = Image::findOrFail($id);
......
......@@ -17,10 +17,9 @@ class InterviewController extends Controller
public function index()
{
$search = request()->query('search');
if($search){ // testa se ha um request de search
if ($search) { // testa se ha um request de search
$interviews = Interview::where('name', 'LIKE', '%' . $search . '%')->paginate(10);
}
else{
} else {
$interviews = Interview::paginate(10);
}
return view('dashboard.entrevista.index')->with(['interviews' => $interviews, 'search' => $search]);
......@@ -46,7 +45,7 @@ class InterviewController extends Controller
{
$request->validate([
'name' => 'required',
'name' => 'required|unique:interviews',
'sumary' => 'required',
'content' => 'required',
'image' => 'required|mimes:jpg,png,jpeg'
......@@ -76,7 +75,7 @@ class InterviewController extends Controller
public function show($id)
{
$interview = Interview::findOrFail($id);
return view('dashboard.entrevista.show')->with(['interview' => $interview]);
}
......@@ -89,7 +88,7 @@ class InterviewController extends Controller
public function edit($id)
{
$interview = Interview::findOrFail($id);
return view('dashboard.entrevista.edit')->with(['interview' => $interview]);
}
......@@ -103,7 +102,7 @@ class InterviewController extends Controller
public function update(Request $request, $id)
{
$request->validate([
'name' => 'required',
'name' => 'required|interviews',
'sumary' => 'required',
'content' => 'required'
]);
......@@ -113,7 +112,7 @@ class InterviewController extends Controller
'name' => $request->input('name'),
'sumary' => $request->input('sumary'),
'content' => $request->input('content')
]);
]);
return redirect('dashboard/entrevista');
}
......
......@@ -20,7 +20,7 @@ class CreateImagesTable extends Migration
$table->string('path');
$table->unsignedInteger('year');
$table->timestamps();
$table->foreign('year')->references('year')->on('image_years')->onDelete('cascade');
//$table->foreign('year')->references('year')->on('image_years')->onDelete('cascade');
});
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment