added changes to custom web pages

This commit is contained in:
ilmedova 2022-02-10 02:12:17 +05:00
parent 0f91e248ba
commit 84a815f19f
5 changed files with 237 additions and 0 deletions

View File

@ -0,0 +1,75 @@
<?php
namespace App\Http\Controllers\Admin;
use Backpack\CRUD\app\Http\Controllers\CrudController;
// VALIDATION: change the requests to match your own file names if you need form validation
use App\Http\Requests\WebpageRequest as StoreRequest;
use App\Http\Requests\WebpageRequest as UpdateRequest;
use Backpack\CRUD\CrudPanel;
/**
* Class WebpageCrudController
* @package App\Http\Controllers\Admin
* @property-read CrudPanel $crud
*/
class WebpageCrudController extends CrudController
{
public function setup()
{
/*
|--------------------------------------------------------------------------
| CrudPanel Basic Information
|--------------------------------------------------------------------------
*/
$this->crud->setModel('App\Models\Webpage');
$this->crud->setRoute(config('backpack.base.route_prefix') . '/webpage');
$this->crud->setEntityNameStrings('webpage', 'webpages');
/*
|--------------------------------------------------------------------------
| CrudPanel Configuration
|--------------------------------------------------------------------------
*/
$this->crud->addColumns([
['name' => 'title', 'type' => 'text', 'label' => 'Title'],
]);
// TODO: remove setFromDb() and manually define Fields and Columns
$this->crud->addFields([
['name' => 'image', 'type' => 'browse', 'label' => 'Image'],
['name' => 'title', 'type' => 'text', 'label' => 'Title'],
['name' => 'text', 'label' => 'Text', 'type' => 'summernote'],
['name' => 'link','type' => 'text', 'lable' => 'Bottom link'],
['name' => 'link_image','type' => 'browse', 'lable' => 'Bottom image'],
['name' => 'upper_link','type' => 'text', 'lable' => 'Upper link'],
['name' => 'upper_image','type' => 'browse', 'lable' => 'Upper image'],
['name' => 'web_banner', 'type' => 'browse', 'label' => 'Web banner'],
['name' => 'mob_banner', 'type' => 'browse', 'label' => 'Mobile banner'],
]);
// add asterisk for fields that are required in WebpageRequest
$this->crud->setRequiredFields(StoreRequest::class, 'create');
$this->crud->setRequiredFields(UpdateRequest::class, 'edit');
}
public function store(StoreRequest $request)
{
// your additional operations before save here
$redirect_location = parent::storeCrud($request);
// your additional operations after save here
// use $this->data['entry'] or $this->crud->entry
return $redirect_location;
}
public function update(UpdateRequest $request)
{
// your additional operations before save here
$redirect_location = parent::updateCrud($request);
// your additional operations after save here
// use $this->data['entry'] or $this->crud->entry
return $redirect_location;
}
}

View File

@ -0,0 +1,56 @@
<?php
namespace App\Http\Requests;
use App\Http\Requests\Request;
use Illuminate\Foundation\Http\FormRequest;
class WebpageRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
// only allow updates if the user is logged in
return backpack_auth()->check();
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
// 'name' => 'required|min:5|max:255'
];
}
/**
* Get the validation attributes that apply to the request.
*
* @return array
*/
public function attributes()
{
return [
//
];
}
/**
* Get the validation messages that apply to the request.
*
* @return array
*/
public function messages()
{
return [
//
];
}
}

65
app/Models/Webpage.php Normal file
View File

@ -0,0 +1,65 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Backpack\CRUD\CrudTrait;
class Webpage extends Model
{
use CrudTrait;
/*
|--------------------------------------------------------------------------
| GLOBAL VARIABLES
|--------------------------------------------------------------------------
*/
protected $table = 'webpages';
// protected $primaryKey = 'id';
// public $timestamps = false;
// protected $guarded = ['id'];
protected $fillable = [
'image', //done
'title', //done
'text', //done
'upper_link', //done
'upper_link_image', //done
'link', //done
'link_image', //done
'web_banner',
'mob_banner'
];
// protected $hidden = [];
// protected $dates = [];
/*
|--------------------------------------------------------------------------
| FUNCTIONS
|--------------------------------------------------------------------------
*/
/*
|--------------------------------------------------------------------------
| RELATIONS
|--------------------------------------------------------------------------
*/
/*
|--------------------------------------------------------------------------
| SCOPES
|--------------------------------------------------------------------------
*/
/*
|--------------------------------------------------------------------------
| ACCESORS
|--------------------------------------------------------------------------
*/
/*
|--------------------------------------------------------------------------
| MUTATORS
|--------------------------------------------------------------------------
*/
}

View File

@ -0,0 +1,40 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateWebpagesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('webpages', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('image')->nullable();
$table->string('title')->nullable();
$table->text('text')->nullable();
$table->string('upper_link')->nullable();
$table->string('upper_link_image')->nullable();
$table->string('link')->nullable();
$table->string('link_image')->nullable();
$table->string('web_banner')->nullable();
$table->string('mob_banner')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('webpages');
}
}

View File

@ -37,4 +37,5 @@ Route::group([
CRUD::resource('gurnawlar', 'GurnawCrudController');
CRUD::resource('folders', 'FolderCrudController');
CRUD::resource('showbukjaorders', 'ShowBukjaOrdersCrudController');
CRUD::resource('webpage', 'WebpageCrudController');
}); // this should be the absolute last line of this file