Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Зуев Егор
/
wiki.dev
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Authored by
Dan Brown
2015-08-09 10:26:54 +0100
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Commit
b2223f16183933ff6a034392044d43b44864e169
b2223f16
1 parent
a4f21e94
Fixed password re-writing and improved book slug creation
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
11 deletions
app/Http/Controllers/BookController.php
app/Repos/BookRepo.php
app/User.php
app/Http/Controllers/BookController.php
View file @
b2223f1
...
...
@@ -61,11 +61,7 @@ class BookController extends Controller
'description'
=>
'string|max:1000'
]);
$book
=
$this
->
bookRepo
->
newFromInput
(
$request
->
all
());
$slug
=
Str
::
slug
(
$book
->
name
);
while
(
$this
->
bookRepo
->
countBySlug
(
$slug
)
>
0
)
{
$slug
.=
'1'
;
}
$book
->
slug
=
$slug
;
$book
->
slug
=
$this
->
bookRepo
->
findSuitableSlug
(
$book
->
name
);
$book
->
created_by
=
Auth
::
user
()
->
id
;
$book
->
updated_by
=
Auth
::
user
()
->
id
;
$book
->
save
();
...
...
@@ -111,11 +107,7 @@ class BookController extends Controller
'description'
=>
'string|max:1000'
]);
$book
->
fill
(
$request
->
all
());
$slug
=
Str
::
slug
(
$book
->
name
);
while
(
$this
->
bookRepo
->
countBySlug
(
$slug
)
>
0
&&
$book
->
slug
!=
$slug
)
{
$slug
+=
'1'
;
}
$book
->
slug
=
$slug
;
$book
->
slug
=
$this
->
bookRepo
->
findSuitableSlug
(
$book
->
name
,
$book
->
id
);
$book
->
updated_by
=
Auth
::
user
()
->
id
;
$book
->
save
();
return
redirect
(
$book
->
getUrl
());
...
...
app/Repos/BookRepo.php
View file @
b2223f1
<?php
namespace
Oxbow\Repos
;
use
Illuminate\Support\Str
;
use
Oxbow\Book
;
class
BookRepo
...
...
@@ -62,4 +63,22 @@ class BookRepo
return
$lastElem
?
$lastElem
->
priority
+
1
:
0
;
}
public
function
doesSlugExist
(
$slug
,
$currentId
=
false
)
{
$query
=
$this
->
book
->
where
(
'slug'
,
'='
,
$slug
);
if
(
$currentId
)
{
$query
=
$query
->
where
(
'id'
,
'!='
,
$currentId
);
}
return
$query
->
count
()
>
0
;
}
public
function
findSuitableSlug
(
$name
,
$currentId
=
false
)
{
$slug
=
Str
::
slug
(
$name
);
while
(
$this
->
doesSlugExist
(
$slug
,
$currentId
))
{
$slug
.=
'-'
.
substr
(
md5
(
rand
(
1
,
500
)),
0
,
3
);
}
return
$slug
;
}
}
\ No newline at end of file
...
...
app/User.php
View file @
b2223f1
...
...
@@ -24,7 +24,7 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
*
* @var array
*/
protected
$fillable
=
[
'name'
,
'email'
,
'password'
];
protected
$fillable
=
[
'name'
,
'email'
];
/**
* The attributes excluded from the model's JSON form.
...
...
Please
register
or
sign in
to post a comment