added contacts

This commit is contained in:
Amanmyrat 2022-12-05 12:54:46 +05:00
parent fadcd1be95
commit d1f7762c23
15 changed files with 486 additions and 4 deletions

View File

@ -0,0 +1,97 @@
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Requests\ContactRequest;
use Backpack\CRUD\app\Http\Controllers\CrudController;
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD;
/**
* Class ContactCrudController
* @package App\Http\Controllers\Admin
* @property-read \Backpack\CRUD\app\Library\CrudPanel\CrudPanel $crud
*/
class ContactCrudController extends CrudController
{
use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\CreateOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\DeleteOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\ShowOperation;
/**
* Configure the CrudPanel object. Apply settings to all operations.
*
* @return void
*/
public function setup()
{
CRUD::setModel(\App\Models\Contact::class);
CRUD::setRoute(config('backpack.base.route_prefix') . '/contact');
CRUD::setEntityNameStrings('contact', 'contacts');
}
/**
* Define what happens when the List operation is loaded.
*
* @see https://backpackforlaravel.com/docs/crud-operation-list-entries
* @return void
*/
protected function setupListOperation()
{
CRUD::column('name');
CRUD::column('contacts');
/**
* Columns can be defined using the fluent syntax or array syntax:
* - CRUD::column('price')->type('number');
* - CRUD::addColumn(['name' => 'price', 'type' => 'number']);
*/
}
/**
* Define what happens when the Create operation is loaded.
*
* @see https://backpackforlaravel.com/docs/crud-operation-create
* @return void
*/
protected function setupCreateOperation()
{
CRUD::setValidation(ContactRequest::class);
CRUD::field('name');
CRUD::field('contacts')->type('repeatable')->fields([
[ // Table
'name' => 'contact',
'label' => 'Contact',
'type' => 'table',
'entity_singular' => 'contact',
'columns' => [
'title' => 'Title',
'phone' => 'Phone',
'mail' => 'Mail',
'fax' => 'Fax'
],
'max' => 2, // maximum rows allowed in the table
'min' => 1, // minimum rows allowed in the table
],
])->new_item_label("Add contact");
/**
* Fields can be defined using the fluent syntax or array syntax:
* - CRUD::field('price')->type('number');
* - CRUD::addField(['name' => 'price', 'type' => 'number']));
*/
}
/**
* Define what happens when the Update operation is loaded.
*
* @see https://backpackforlaravel.com/docs/crud-operation-update
* @return void
*/
protected function setupUpdateOperation()
{
$this->setupCreateOperation();
}
}

View File

@ -39,7 +39,7 @@ class MultimediaCrudController extends CrudController
*/
protected function setupListOperation()
{
CRUD::column('category_id');
CRUD::column('multimedia_category_id');
CRUD::column('title');
CRUD::column('media');
@ -60,7 +60,7 @@ class MultimediaCrudController extends CrudController
{
CRUD::setValidation(MultimediaRequest::class);
CRUD::field('category_id');
CRUD::field('multimedia_category_id');
CRUD::field('title');
CRUD::field('media')->type('upload')->upload(true);

View File

@ -0,0 +1,86 @@
<?php
namespace App\Http\Controllers;
use App\Models\Contact;
use App\Http\Requests\StoreContactRequest;
use App\Http\Requests\UpdateContactRequest;
class ContactController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*
* @param \App\Http\Requests\StoreContactRequest $request
* @return \Illuminate\Http\Response
*/
public function store(StoreContactRequest $request)
{
//
}
/**
* Display the specified resource.
*
* @param \App\Models\Contact $contact
* @return \Illuminate\Http\Response
*/
public function show(Contact $contact)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param \App\Models\Contact $contact
* @return \Illuminate\Http\Response
*/
public function edit(Contact $contact)
{
//
}
/**
* Update the specified resource in storage.
*
* @param \App\Http\Requests\UpdateContactRequest $request
* @param \App\Models\Contact $contact
* @return \Illuminate\Http\Response
*/
public function update(UpdateContactRequest $request, Contact $contact)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param \App\Models\Contact $contact
* @return \Illuminate\Http\Response
*/
public function destroy(Contact $contact)
{
//
}
}

View File

@ -66,7 +66,7 @@ class TradingController extends Controller
{
request()->validate([
'group' => ['exists:groups,id'],
'file' => ['required', 'mimes:xlsx'],
'file' => ['required', 'mimes:xlsx, csv, xls'],
]);
if (!$group = Group::find(request('group'))) {

View File

@ -0,0 +1,55 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class ContactRequest 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 [
//
];
}
}

View File

@ -0,0 +1,30 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class StoreContactRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return false;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
//
];
}
}

View File

@ -0,0 +1,30 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class UpdateContactRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return false;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
//
];
}
}

17
app/Models/Contact.php Normal file
View File

@ -0,0 +1,17 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Backpack\CRUD\app\Models\Traits\SpatieTranslatable\HasTranslations;
class Contact extends Model
{
use \Backpack\CRUD\app\Models\Traits\CrudTrait;
use HasFactory;
use HasTranslations;
protected $guarded = ['id'];
public $translatable = ['name', 'contacts'];
}

View File

@ -0,0 +1,94 @@
<?php
namespace App\Policies;
use App\Models\Contact;
use App\Models\User;
use Illuminate\Auth\Access\HandlesAuthorization;
class ContactPolicy
{
use HandlesAuthorization;
/**
* Determine whether the user can view any models.
*
* @param \App\Models\User $user
* @return \Illuminate\Auth\Access\Response|bool
*/
public function viewAny(User $user)
{
//
}
/**
* Determine whether the user can view the model.
*
* @param \App\Models\User $user
* @param \App\Models\Contact $contact
* @return \Illuminate\Auth\Access\Response|bool
*/
public function view(User $user, Contact $contact)
{
//
}
/**
* Determine whether the user can create models.
*
* @param \App\Models\User $user
* @return \Illuminate\Auth\Access\Response|bool
*/
public function create(User $user)
{
//
}
/**
* Determine whether the user can update the model.
*
* @param \App\Models\User $user
* @param \App\Models\Contact $contact
* @return \Illuminate\Auth\Access\Response|bool
*/
public function update(User $user, Contact $contact)
{
//
}
/**
* Determine whether the user can delete the model.
*
* @param \App\Models\User $user
* @param \App\Models\Contact $contact
* @return \Illuminate\Auth\Access\Response|bool
*/
public function delete(User $user, Contact $contact)
{
//
}
/**
* Determine whether the user can restore the model.
*
* @param \App\Models\User $user
* @param \App\Models\Contact $contact
* @return \Illuminate\Auth\Access\Response|bool
*/
public function restore(User $user, Contact $contact)
{
//
}
/**
* Determine whether the user can permanently delete the model.
*
* @param \App\Models\User $user
* @param \App\Models\Contact $contact
* @return \Illuminate\Auth\Access\Response|bool
*/
public function forceDelete(User $user, Contact $contact)
{
//
}
}

View File

@ -0,0 +1,20 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
class ContactFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
//
];
}
}

View File

@ -0,0 +1,33 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateContactsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('contacts', function (Blueprint $table) {
$table->id();
$table->text('name');
$table->longText('contacts');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('contacts');
}
}

View File

@ -0,0 +1,18 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
class ContactSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
//
}
}

View File

@ -18,3 +18,5 @@
<li class="nav-item"><a class="nav-link" href="{{ backpack_url('news') }}"><i class="nav-icon la la-question"></i> News</a></li>
<li class='nav-item'><a class='nav-link' href='{{ backpack_url('document') }}'><i class='nav-icon la la-question'></i> Documents</a></li>
<li class="nav-item"><a class="nav-link" href="{{ backpack_url('tarif') }}"><i class="nav-icon la la-question"></i> Tarifs</a></li>
<li class="nav-item"><a class="nav-link" href="{{ backpack_url('contact') }}"><i class="nav-icon la la-question"></i> Contacts</a></li>

View File

@ -25,4 +25,5 @@ Route::group([
Route::crud('tarif', 'TarifCrudController');
Route::crud('multimedia-category', 'MultimediaCategoryCrudController');
Route::crud('multimedia', 'MultimediaCrudController');
Route::crud('contact', 'ContactCrudController');
}); // this should be the absolute last line of this file

View File

@ -33,7 +33,6 @@ Route::group(['middleware' => 'check_october_session'], function () {
Route::get('lang/{lang}', [HomeController::class, 'lang'])->name('lang');
});
Route::group(['middleware' => 'auth:sanctum'], function () {
Route::post('imports/import', [ImportController::class, 'import'])->name('imports.import');
Route::post('exports/import', [ExportController::class, 'import'])->name('exports.import');