Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QuickAdminPanel file update #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions app/Asset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Spatie\MediaLibrary\HasMedia\HasMedia;
use Spatie\MediaLibrary\HasMedia\HasMediaTrait;
use Spatie\MediaLibrary\Models\Media;

class Asset extends Model implements HasMedia
{
use SoftDeletes, HasMediaTrait;

public $table = 'assets';

protected $appends = [
'photos',
];

protected $dates = [
'created_at',
'updated_at',
'deleted_at',
];

protected $fillable = [
'name',
'notes',
'status_id',
'created_at',
'updated_at',
'deleted_at',
'category_id',
'location_id',
'serial_number',
'assigned_to_id',
];

public static function boot()
{
parent::boot();
Asset::observe(new \App\Observers\AssetsHistoryObserver);
}

public function registerMediaConversions(Media $media = null)
{
$this->addMediaConversion('thumb')->width(50)->height(50);
}

public function assetsHistories()
{
return $this->hasMany(AssetsHistory::class, 'asset_id', 'id');
}

public function category()
{
return $this->belongsTo(AssetCategory::class, 'category_id');
}

public function getPhotosAttribute()
{
return $this->getMedia('photos');
}

public function status()
{
return $this->belongsTo(AssetStatus::class, 'status_id');
}

public function location()
{
return $this->belongsTo(AssetLocation::class, 'location_id');
}

public function assigned_to()
{
return $this->belongsTo(User::class, 'assigned_to_id');
}
}
31 changes: 31 additions & 0 deletions app/AssetCategory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class AssetCategory extends Model
{
use SoftDeletes;

public $table = 'asset_categories';

protected $dates = [
'created_at',
'updated_at',
'deleted_at',
];

protected $fillable = [
'name',
'created_at',
'updated_at',
'deleted_at',
];

public function assets()
{
return $this->hasMany(Asset::class, 'category_id', 'id');
}
}
36 changes: 36 additions & 0 deletions app/AssetLocation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class AssetLocation extends Model
{
use SoftDeletes;

public $table = 'asset_locations';

protected $dates = [
'created_at',
'updated_at',
'deleted_at',
];

protected $fillable = [
'name',
'created_at',
'updated_at',
'deleted_at',
];

public function assets()
{
return $this->hasMany(Asset::class, 'location_id', 'id');
}

public function assetsHistories()
{
return $this->hasMany(AssetsHistory::class, 'location_id', 'id');
}
}
36 changes: 36 additions & 0 deletions app/AssetStatus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class AssetStatus extends Model
{
use SoftDeletes;

public $table = 'asset_statuses';

protected $dates = [
'created_at',
'updated_at',
'deleted_at',
];

protected $fillable = [
'name',
'created_at',
'updated_at',
'deleted_at',
];

public function assets()
{
return $this->hasMany(Asset::class, 'status_id', 'id');
}

public function assetsHistories()
{
return $this->hasMany(AssetsHistory::class, 'status_id', 'id');
}
}
44 changes: 44 additions & 0 deletions app/AssetsHistory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class AssetsHistory extends Model
{
public $table = 'assets_histories';

protected $dates = [
'created_at',
'updated_at',
];

protected $fillable = [
'asset_id',
'status_id',
'created_at',
'updated_at',
'location_id',
'assigned_user_id',
];

public function asset()
{
return $this->belongsTo(Asset::class, 'asset_id');
}

public function status()
{
return $this->belongsTo(AssetStatus::class, 'status_id');
}

public function location()
{
return $this->belongsTo(AssetLocation::class, 'location_id');
}

public function assigned_user()
{
return $this->belongsTo(User::class, 'assigned_user_id');
}
}
75 changes: 75 additions & 0 deletions app/Http/Controllers/Admin/AssetCategoryController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

namespace App\Http\Controllers\Admin;

use App\AssetCategory;
use App\Http\Controllers\Controller;
use App\Http\Requests\MassDestroyAssetCategoryRequest;
use App\Http\Requests\StoreAssetCategoryRequest;
use App\Http\Requests\UpdateAssetCategoryRequest;
use Gate;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;

class AssetCategoryController extends Controller
{
public function index()
{
abort_if(Gate::denies('asset_category_access'), Response::HTTP_FORBIDDEN, '403 Forbidden');

$assetCategories = AssetCategory::all();

return view('admin.assetCategories.index', compact('assetCategories'));
}

public function create()
{
abort_if(Gate::denies('asset_category_create'), Response::HTTP_FORBIDDEN, '403 Forbidden');

return view('admin.assetCategories.create');
}

public function store(StoreAssetCategoryRequest $request)
{
$assetCategory = AssetCategory::create($request->all());

return redirect()->route('admin.asset-categories.index');
}

public function edit(AssetCategory $assetCategory)
{
abort_if(Gate::denies('asset_category_edit'), Response::HTTP_FORBIDDEN, '403 Forbidden');

return view('admin.assetCategories.edit', compact('assetCategory'));
}

public function update(UpdateAssetCategoryRequest $request, AssetCategory $assetCategory)
{
$assetCategory->update($request->all());

return redirect()->route('admin.asset-categories.index');
}

public function show(AssetCategory $assetCategory)
{
abort_if(Gate::denies('asset_category_show'), Response::HTTP_FORBIDDEN, '403 Forbidden');

return view('admin.assetCategories.show', compact('assetCategory'));
}

public function destroy(AssetCategory $assetCategory)
{
abort_if(Gate::denies('asset_category_delete'), Response::HTTP_FORBIDDEN, '403 Forbidden');

$assetCategory->delete();

return back();
}

public function massDestroy(MassDestroyAssetCategoryRequest $request)
{
AssetCategory::whereIn('id', request('ids'))->delete();

return response(null, Response::HTTP_NO_CONTENT);
}
}
Loading