tethys/app/Http/Controllers/BookController.php

83 lines
2.3 KiB
PHP
Raw Normal View History

2018-08-06 12:30:51 +00:00
<?php
namespace App\Http\Controllers;
2015-07-19 06:49:24 +00:00
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Book;
2018-09-10 13:09:10 +00:00
use App\Models\Project;
2015-07-19 06:49:24 +00:00
use App\Shelf;
use App\Http\Requests\BookRequest;
use Illuminate\Http\Request;
2018-08-06 12:30:51 +00:00
use Illuminate\View\View;
class BookController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
public function index() : View
{
//$books = Book::with('category', 'shelf')->get();
$books = Book::with('project')->get();
return view('rdr.settings.book.book', compact('books'));
}
public function add()
{
$categories = Project::pluck('name', 'id');
$shelves = Shelf::pluck('shelf', 'id');
$datum = date('Y-m-d');
$nowYear = substr($datum, 0, 4);
$years = array();
for ($jahr = 1990; $jahr <= $nowYear; $jahr++) {
$years[$jahr] = $jahr;
}
return view('rdr.settings.book.add', compact('categories', 'shelves', 'years'));
}
public function store(BookRequest $request)
{
$input = $request->all();
$book = Book::create($input);
session()->flash('flash_message', 'You have been addded 1 book!');
return redirect()->route('settings.book');
}
public function edit($id)
{
$book = Book::findOrFail($id);
$categories = Project::pluck('name', 'id');
// $shelves = Shelf::pluck('shelf', 'id');
$datum = date('Y-m-d');
$nowYear = substr($datum, 0, 4);
$years = array();
for ($jahr = 1990; $jahr <= $nowYear; $jahr++) {
$years[$jahr] = $jahr;
}
return view('rdr.settings.book.edit', compact('book', 'categories', 'years'));
//return view('rdr.settings.book.edit', compact('book', 'categories', 'shelves', 'years'));
}
public function update($id, BookRequest $request)
{
$book = Book::findOrFail($id);
$input = $request->all();
$book->update($input);
session()->flash('flash_message', 'You have updated 1 book!');
return redirect()->route('settings.book');
}
public function delete($id)
{
$book = Book::findOrFail($id);
$book->delete();
session()->flash('flash_message', 'You have deleted 1 book!');
return redirect()->route('settings.book');
}
2015-07-19 06:49:24 +00:00
}