Skip to content

Commit

Permalink
books commit
Browse files Browse the repository at this point in the history
  • Loading branch information
thaerfayyad committed Mar 5, 2021
1 parent 1d2f256 commit bb7fe46
Show file tree
Hide file tree
Showing 16 changed files with 394 additions and 187 deletions.
35 changes: 35 additions & 0 deletions app/Http/Controllers/Site/BookController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace App\Http\Controllers\Site;

use App\Http\Controllers\Controller;
use App\Models\admin\Book;
use Illuminate\Http\Request;
use DB;
class BookController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
//
}

/**
* Show the application dashboard.
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function student()
{


$books = Book::where('library', 1)->get();

return view('site.books.index', compact('books'));
}

}
20 changes: 16 additions & 4 deletions app/Http/Controllers/Site/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,22 @@ public function __construct()
*/
public function index()
{



return view('site.index');
$chartjs = app()->chartjs
->name('pieChartTest')
->type('pie')
->size(['width' => 400, 'height' => 200])
->labels(['Label x', 'Label y'])
->datasets([
[
'backgroundColor' => ['#FF6384', '#36A2EB'],
'hoverBackgroundColor' => ['#FF6384', '#36A2EB'],
'data' => [69, 59]
]
])
->options([]);


return view('site.index', compact('chartjs'));
}

}
69 changes: 45 additions & 24 deletions app/Http/Controllers/admin/bookController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Models\admin\book;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\Storage;

class bookController extends Controller
{
Expand All @@ -16,24 +17,10 @@ class bookController extends Controller
*/
public function index()
{
$chartjs = app()->chartjs
->name('pieChartTest')
->type('pie')
->size(['width' => 400, 'height' => 200])
->labels(['Label x', 'Label y'])
->datasets([
[
'backgroundColor' => ['#FF6384', '#36A2EB'],
'hoverBackgroundColor' => ['#FF6384', '#36A2EB'],
'data' => [69, 59]
]
])
->options([]);
$items = Book::all();
return view('admin.books.home',
[
'items' =>$items,
'chartjs' =>$chartjs,
]);
}

Expand All @@ -55,17 +42,25 @@ public function create()
*/
public function store(Request $request)
{
// dd($request->all());
$validator = Validator::make($request->all(), [
'name' => 'required',
'details' => 'required',
'file' => 'mimes:doc,pdf,docx,zip'
'author' => 'required',
'yearFrom' => 'required',
'semester' => 'required',
'bookFile' => 'mimes:doc,pdf,docx,zip'
]);
$book = new Book();
$book->name = $request->name;
$book->details = $request->details ;
$book->author = $request->author ;
$book->file = $request->file ;
$book->save();

if( $request->bookFile != Null) {

$book = $request->file('bookFile');
$book_new_name = time() . "-" . $book->getClientOriginalName();
$book->storeAs('uploads/books', $book_new_name);
$book->bookFile = $book_new_name;
}

Book::create($request->except('_token'));

return redirect()->back();
}
Expand All @@ -89,7 +84,9 @@ public function show($id)
*/
public function edit($id)
{
//
$book = Book::findOrFail($id);

return view('admin.books.edit' , compact('book'));
}

/**
Expand All @@ -101,7 +98,29 @@ public function edit($id)
*/
public function update(Request $request, $id)
{
//
// dd($request->all());
$request->validate([
'name' => 'required|max:255',
'details' => 'required',
'author' => 'required',
'year' => 'required',
'semester' => 'required',
'library' => 'required',
'bookFile' => 'mimes:doc,pdf,docx,zip'
]);
$item = Book::findOrFail($id);
if( $request->bookFile != Null) {

$book = $request->file('bookFile');
$book_new_name = time() . "-" . $book->getClientOriginalName();
$book->storeAs('uploads/books', $book_new_name);
$book->bookFile = $book_new_name;
}

$item ->update($request->except('_token'));
return redirect()->route('books.index')
->with('success', 'Book updated successfully');

}

/**
Expand All @@ -112,6 +131,8 @@ public function update(Request $request, $id)
*/
public function destroy($id)
{
//
Book::findOrFail($id)->delete();
return redirect()->route('books.index')
->with('success', 'Book Deleted Successfully');
}
}
9 changes: 7 additions & 2 deletions app/Models/admin/Book.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ class Book extends Model
{
use SoftDeletes;
protected $table = 'books';
protected $fillable = ['name','author','file','details'];
protected $guarded = [];
protected $hidden = ['created_at',' updated_at','deleted_at'];

public function getSemester(){
return $this -> semester== 1 ? 'semester"1" ' : 'semester "2" ';
}
public function getLibrary(){
return $this -> semester== 1 ? 'General ' : 'Student ';
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"php": "^7.2.5",
"fideloper/proxy": "^4.2",
"fruitcake/laravel-cors": "^1.0",
"fx3costa/laravelchartjs": "^2.8",
"fx3costa/laravelchartjs": "^2.8.0",
"guzzlehttp/guzzle": "^6.3",
"laravel/framework": "^7.0",
"laravel/tinker": "^2.0",
Expand Down
Loading

0 comments on commit bb7fe46

Please sign in to comment.