diff --git a/app/Http/Controllers/BookController.php b/app/Http/Controllers/BookController.php index 8996ae64a..086929558 100644 --- a/app/Http/Controllers/BookController.php +++ b/app/Http/Controllers/BookController.php @@ -40,7 +40,7 @@ class BookController extends Controller $recents = $this->signedIn ? $this->entityRepo->getRecentlyViewed('book', 4, 0) : false; $popular = $this->entityRepo->getPopular('book', 4, 0); $this->setPageTitle('Books'); - return view('books/index', ['books' => $books, 'recents' => $recents, 'popular' => $popular]); + return view('books/index', ['books' => $books, 'recents' => $recents, 'popular' => $popular, 'display' => $display]); //added displaly to access user display } /** @@ -67,7 +67,14 @@ class BookController extends Controller 'name' => 'required|string|max:255', 'description' => 'string|max:1000' ]); + $image = $request->file('image'); + $input = time().'-'.$image->getClientOriginalName(); + $destinationPath = public_path('uploads/book/'); + $image->move($destinationPath, $input); + $path = baseUrl('/uploads/book/').'/'.$input; $book = $this->entityRepo->createFromInput('book', $request->all()); + $book->image = $path; + $book->save(); Activity::add($book, 'book_create', $book->id); return redirect($book->getUrl()); } @@ -114,9 +121,17 @@ class BookController extends Controller 'name' => 'required|string|max:255', 'description' => 'string|max:1000' ]); - $book = $this->entityRepo->updateFromInput('book', $book, $request->all()); - Activity::add($book, 'book_update', $book->id); - return redirect($book->getUrl()); + + $input = $request->file('image')->getClientOriginalName(); + echo $input; + $destinationPath = public_path('uploads/book/'); + $request->file('image')->move($destinationPath, $input); + $path = baseUrl('/uploads/book/').'/'.$input; + $book = $this->entityRepo->updateFromInput('book', $book, $request->all()); + $book->image = $path; + $book->save(); + Activity::add($book, 'book_update', $book->id); + return redirect($book->getUrl()); } /** diff --git a/app/User.php b/app/User.php index 8033557e4..3d77cd8ee 100644 --- a/app/User.php +++ b/app/User.php @@ -22,7 +22,7 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon * The attributes that are mass assignable. * @var array */ - protected $fillable = ['name', 'email', 'image_id']; + protected $fillable = ['name', 'email', 'image_id', 'display']; //to write in user database /** * The attributes excluded from the model's JSON form. diff --git a/resources/lang/en/common.php b/resources/lang/en/common.php index e1d74c95e..dae6d0509 100644 --- a/resources/lang/en/common.php +++ b/resources/lang/en/common.php @@ -44,6 +44,7 @@ return [ 'no_items' => 'No items available', 'back_to_top' => 'Back to top', 'toggle_details' => 'Toggle Details', + 'toggle_thumbnails' => 'Toggle Thumbnails', /** * Header diff --git a/resources/views/books/create.blade.php b/resources/views/books/create.blade.php index 2c629e699..36c94af62 100644 --- a/resources/views/books/create.blade.php +++ b/resources/views/books/create.blade.php @@ -4,7 +4,7 @@

{{ trans('entities.books_create') }}

-
+ @include('books/form')
diff --git a/resources/views/books/edit.blade.php b/resources/views/books/edit.blade.php index 2419b68da..02768b301 100644 --- a/resources/views/books/edit.blade.php +++ b/resources/views/books/edit.blade.php @@ -14,7 +14,7 @@

{{ trans('entities.books_edit') }}

-
+ @include('books/form', ['model' => $book])
diff --git a/resources/views/books/form.blade.php b/resources/views/books/form.blade.php index b1484d129..e5ee47a82 100644 --- a/resources/views/books/form.blade.php +++ b/resources/views/books/form.blade.php @@ -10,6 +10,10 @@ @include('form/textarea', ['name' => 'description'])
+
+ + +
{{ trans('common.cancel') }} diff --git a/resources/views/books/grid-item.blade.php b/resources/views/books/grid-item.blade.php new file mode 100644 index 000000000..a37458ec6 --- /dev/null +++ b/resources/views/books/grid-item.blade.php @@ -0,0 +1,15 @@ +
+
+

+ {{$book->name}} +
+ image === NULL) src="{{baseUrl('/default.jpg')}}" @else src="{{$book->image}}" @endif alt="{{$book->name}}"> +
+

+ @if(isset($book->searchSnippet)) +

{!! $book->searchSnippet !!}

+ @else +

{{ $book->getExcerpt() }}

+ @endif +
+
\ No newline at end of file diff --git a/resources/views/books/index.blade.php b/resources/views/books/index.blade.php index c090a127e..76e521633 100644 --- a/resources/views/books/index.blade.php +++ b/resources/views/books/index.blade.php @@ -5,12 +5,12 @@
-
-
+
@if($currentUser->can('book-create-all')) {{ trans('entities.books_create') }} @endif + {{ trans('common.toggle_thumbnails') }}
@@ -20,14 +20,19 @@
-
+

{{ trans('entities.books') }}

+ {!! $books->render() !!} @if(count($books) > 0) + @if($display=='grid') + @foreach($books as $book) + @include('books/grid-item', ['book' => $book]) + @endforeach + @else @foreach($books as $book) - @include('books/list-item', ['book' => $book]) -
- @endforeach - {!! $books->render() !!} + @include('books/list-item', ['book' => $book]) + @endforeach + @endif @else

{{ trans('entities.books_empty') }}

@if(userCan('books-create-all')) @@ -35,7 +40,7 @@ @endif @endif
-
+
@if($recents)
 
@@ -53,6 +58,7 @@ @endif
+ {!! $books->render() !!}
diff --git a/resources/views/users/edit.blade.php b/resources/views/users/edit.blade.php index ff3475194..3cacff645 100644 --- a/resources/views/users/edit.blade.php +++ b/resources/views/users/edit.blade.php @@ -49,6 +49,15 @@ @endforeach
+ +
+ + +
+