Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
PET Computação
Re-rememberPET
Commits
0be9f75d
Commit
0be9f75d
authored
2 years ago
by
gop20
Browse files
Options
Download
Email Patches
Plain Diff
adicionado validacao
parent
59303371
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
remember_laravel/app/Http/Controllers/GalleryController.php
+26
-15
remember_laravel/app/Http/Controllers/GalleryController.php
remember_laravel/app/Http/Controllers/InterviewController.php
+7
-8
...mber_laravel/app/Http/Controllers/InterviewController.php
remember_laravel/database/migrations/2021_10_26_180313_create_images_table.php
+1
-1
...base/migrations/2021_10_26_180313_create_images_table.php
with
34 additions
and
24 deletions
+34
-24
remember_laravel/app/Http/Controllers/GalleryController.php
+
26
-
15
View file @
0be9f75d
...
...
@@ -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
);
...
...
This diff is collapsed.
Click to expand it.
remember_laravel/app/Http/Controllers/InterviewController.php
+
7
-
8
View file @
0be9f75d
...
...
@@ -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'
);
}
...
...
This diff is collapsed.
Click to expand it.
remember_laravel/database/migrations/2021_10_26_180313_create_images_table.php
+
1
-
1
View file @
0be9f75d
...
...
@@ -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');
});
}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help