ANG YU 5 лет назад
Родитель
Сommit
ee65bcb26c

+ 7 - 0
app/CustomerLog.php

@@ -3,8 +3,15 @@
 namespace App;
 
 use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\Relations\BelongsTo;
 
 class CustomerLog extends Model
 {
     protected $fillable = ['customer_id', 'customer_log_status_id', 'user_id', 'description'];
+    protected $guarded = ['id'];
+
+    public function customerLogStatus(): BelongsTo
+    {
+        return $this->belongsTo(CustomerLogStatus::class);
+    }
 }

+ 11 - 0
app/CustomerLogStatus.php

@@ -0,0 +1,11 @@
+<?php
+
+namespace App;
+
+use Illuminate\Database\Eloquent\Model;
+
+class CustomerLogStatus extends Model
+{
+    protected $fillable = ['name', 'description'];
+    protected $guarded = ['id'];
+}

+ 57 - 0
app/Http/Controllers/CustomerLogStatusesController.php

@@ -0,0 +1,57 @@
+<?php
+
+namespace App\Http\Controllers;
+
+use App\CustomerLogStatus;
+
+class CustomerLogStatusesController extends Controller
+{
+    public function __construct()
+    {
+        $this->middleware('auth', ['except' => ['index', 'show']]);
+    }
+
+    public function index()
+    {
+        $customer_log_statuses = CustomerLogStatus::paginate();
+        return view('customer_log_statuses.index', compact('customer_log_statuses'));
+    }
+
+    public function show(CustomerLogStatus $customer_log_status)
+    {
+        return view('customer_log_statuses.show', compact('customer_log_status'));
+    }
+
+    public function create(CustomerLogStatus $customer_log_status)
+    {
+        return view('customer_log_statuses.create_and_edit', compact('customer_log_status'));
+    }
+
+    public function store($request)
+    {
+        $customer_log_status = CustomerLogStatus::create($request->all());
+        return redirect()->route('customer_log_statuses.show', $customer_log_status->id)->with('message', 'Created successfully.');
+    }
+
+    public function edit(CustomerLogStatus $customer_log_status)
+    {
+        $this->authorize('update', $customer_log_status);
+        return view('customer_log_statuses.create_and_edit', compact('customer_log_status'));
+    }
+
+    public function update($request, CustomerLogStatus $customer_log_status)
+    {
+        $this->authorize('update', $customer_log_status);
+        $customer_log_status->update($request->all());
+
+        return redirect()->route('customer_log_statuses.show', $customer_log_status->id)->with('message', 'Updated successfully.');
+    }
+
+    public function destroy(CustomerLogStatus $customer_log_status)
+    {
+        $this->authorize('destroy', $customer_log_status);
+        $customer_log_status->delete();
+
+        return redirect()->route('customer_log_statuses.index')->with('message', 'Deleted successfully.');
+    }
+}

+ 15 - 1
database/factories/CustomerLogFactory.php

@@ -1,9 +1,23 @@
 <?php
+/** @var Factory $factory */
 
+use App\Customer;
+use App\CustomerLogStatus;
+use App\User;
 use Faker\Generator as Faker;
+use Illuminate\Database\Eloquent\Factory;
 
 $factory->define(App\CustomerLog::class, function (Faker $faker) {
     return [
-        // 'name' => $faker->name,
+        'customer_id' => function () {
+            return factory(Customer::class)->create()->id;
+        },
+        'customer_log_status_id' =>  function () {
+            return factory(CustomerLogStatus::class)->create()->id;
+        },
+        'user_id' => function () {
+            return factory(User::class)->create()->id;
+        },
+        'description' => $faker->text,
     ];
 });

+ 12 - 0
database/factories/CustomerLogStatusFactory.php

@@ -0,0 +1,12 @@
+<?php
+/** @var Factory $factory */
+
+use Faker\Generator as Faker;
+use Illuminate\Database\Eloquent\Factory;
+
+$factory->define(App\CustomerLogStatus::class, function (Faker $faker) {
+    return [
+        'name' => $faker->title,
+        'description' => $faker->text,
+    ];
+});

+ 23 - 0
database/migrations/2020_12_14_103401_create_customerlogstatuses_table.php

@@ -0,0 +1,23 @@
+<?php
+
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Support\Facades\Schema;
+
+class CreateCustomerLogStatusesTable extends Migration
+{
+	public function up()
+	{
+		Schema::create('customer_log_statuses', function(Blueprint $table) {
+            $table->increments('id');
+            $table->string('name')->index();
+            $table->text('description');
+            $table->timestamps();
+        });
+	}
+
+	public function down()
+	{
+		Schema::drop('customer_log_statuses');
+	}
+}

+ 20 - 0
database/seeds/CustomerLogStatusesTableSeeder.php

@@ -0,0 +1,20 @@
+<?php
+
+use App\CustomerLogStatus;
+use Illuminate\Database\Seeder;
+
+class CustomerLogStatusesTableSeeder extends Seeder
+{
+    public function run()
+    {
+        $customer_log_statuses = factory(CustomerLogStatus::class)->times(50)->make()->each(function ($customer_log_status, $index) {
+            if ($index == 0) {
+                // $customer_log_status->field = 'value';
+            }
+        });
+
+        CustomerLogStatus::insert($customer_log_statuses->toArray());
+    }
+
+}
+

+ 52 - 0
resources/views/customer_log_statuses/create_and_edit.blade.php

@@ -0,0 +1,52 @@
+@extends('layouts.app')
+
+@section('content')
+
+<div class="container">
+  <div class="col-md-10 offset-md-1">
+    <div class="card ">
+
+      <div class="card-header">
+        <h1>
+          CustomerLogStatus /
+          @if($customer_log_status->id)
+            Edit #{{ $customer_log_status->id }}
+          @else
+            Create
+          @endif
+        </h1>
+      </div>
+
+      <div class="card-body">
+        @if($customer_log_status->id)
+          <form action="{{ route('customer_log_statuses.update', $customer_log_status->id) }}" method="POST" accept-charset="UTF-8">
+          <input type="hidden" name="_method" value="PUT">
+        @else
+          <form action="{{ route('customer_log_statuses.store') }}" method="POST" accept-charset="UTF-8">
+        @endif
+
+          @include('common.error')
+
+          <input type="hidden" name="_token" value="{{ csrf_token() }}">
+
+          
+                <div class="form-group">
+                	<label for="name-field">Name</label>
+                	<input class="form-control" type="text" name="name" id="name-field" value="{{ old('name', $customer_log_status->name ) }}" />
+                </div> 
+                <div class="form-group">
+                	<label for="description-field">Description</label>
+                	<textarea name="description" id="description-field" class="form-control" rows="3">{{ old('description', $customer_log_status->description ) }}</textarea>
+                </div>
+
+          <div class="well well-sm">
+            <button type="submit" class="btn btn-primary">Save</button>
+            <a class="btn btn-link float-xs-right" href="{{ route('customer_log_statuses.index') }}"> <- Back</a>
+          </div>
+        </form>
+      </div>
+    </div>
+  </div>
+</div>
+
+@endsection

+ 61 - 0
resources/views/customer_log_statuses/index.blade.php

@@ -0,0 +1,61 @@
+@extends('layouts.app')
+
+@section('content')
+<div class="container">
+  <div class="col-md-10 offset-md-1">
+    <div class="card ">
+      <div class="card-header">
+        <h1>
+          CustomerLogStatus
+          <a class="btn btn-success float-xs-right" href="{{ route('customer_log_statuses.create') }}">Create</a>
+        </h1>
+      </div>
+
+      <div class="card-body">
+        @if($customer_log_statuses->count())
+          <table class="table table-sm table-striped">
+            <thead>
+              <tr>
+                <th class="text-xs-center">#</th>
+                <th>Name</th> <th>Description</th>
+                <th class="text-xs-right">OPTIONS</th>
+              </tr>
+            </thead>
+
+            <tbody>
+              @foreach($customer_log_statuses as $customer_log_status)
+              <tr>
+                <td class="text-xs-center"><strong>{{$customer_log_status->id}}</strong></td>
+
+                <td>{{$customer_log_status->name}}</td> <td>{{$customer_log_status->description}}</td>
+
+                <td class="text-xs-right">
+                  <a class="btn btn-sm btn-primary" href="{{ route('customer_log_statuses.show', $customer_log_status->id) }}">
+                    V
+                  </a>
+
+                  <a class="btn btn-sm btn-warning" href="{{ route('customer_log_statuses.edit', $customer_log_status->id) }}">
+                    E
+                  </a>
+
+                  <form action="{{ route('customer_log_statuses.destroy', $customer_log_status->id) }}" method="POST" style="display: inline;" onsubmit="return confirm('Delete? Are you sure?');">
+                    {{csrf_field()}}
+                    <input type="hidden" name="_method" value="DELETE">
+
+                    <button type="submit" class="btn btn-sm btn-danger">D </button>
+                  </form>
+                </td>
+              </tr>
+              @endforeach
+            </tbody>
+          </table>
+          {!! $customer_log_statuses->render() !!}
+        @else
+          <h3 class="text-xs-center alert alert-info">Empty!</h3>
+        @endif
+      </div>
+    </div>
+  </div>
+</div>
+
+@endsection

+ 39 - 0
resources/views/customer_log_statuses/show.blade.php

@@ -0,0 +1,39 @@
+@extends('layouts.app')
+
+@section('content')
+
+<div class="container">
+  <div class="col-md-10 offset-md-1">
+    <div class="card ">
+      <div class="card-header">
+        <h1>CustomerLogStatus / Show #{{ $customer_log_status->id }}</h1>
+      </div>
+
+      <div class="card-body">
+        <div class="card-block bg-light">
+          <div class="row">
+            <div class="col-md-6">
+              <a class="btn btn-link" href="{{ route('customer_log_statuses.index') }}"><- Back</a>
+            </div>
+            <div class="col-md-6">
+              <a class="btn btn-sm btn-warning float-right mt-1" href="{{ route('customer_log_statuses.edit', $customer_log_status->id) }}">
+                Edit
+              </a>
+            </div>
+          </div>
+        </div>
+        <br>
+
+        <label>Name</label>
+<p>
+	{{ $customer_log_status->name }}
+</p> <label>Description</label>
+<p>
+	{{ $customer_log_status->description }}
+</p>
+      </div>
+    </div>
+  </div>
+</div>
+
+@endsection

+ 2 - 1
routes/web.php

@@ -613,4 +613,5 @@ Route::group(['prefix'=>'control'],function () {
    Route::get('panel/menu','ControlPanelController@index') ;
 });
 
-Route::resource('customer_logs', 'CustomerLogsController', ['only' => ['index', 'show', 'create', 'store', 'update', 'edit', 'destroy']]);
+Route::resource('customer_logs', 'CustomerLogsController', ['only' => ['index', 'show', 'create', 'store', 'update', 'edit', 'destroy']]);
+Route::resource('customer_log_statuses', 'CustomerLogStatusesController', ['only' => ['index', 'show', 'create', 'store', 'update', 'edit', 'destroy']]);

+ 21 - 0
tests/Unit/CustomerLogTest.php

@@ -0,0 +1,21 @@
+<?php
+
+
+use App\CustomerLog;
+use Illuminate\Database\Eloquent\Relations\BelongsTo;
+use Illuminate\Foundation\Testing\RefreshDatabase;
+use Tests\TestCase;
+
+class CustomerLogTest extends TestCase
+{
+    use RefreshDatabase;
+
+    /**
+     * @test
+     */
+    public function customerLog_belongsTo_customerLogStatus()
+    {
+        $customerLog =  factory(CustomerLog::class)->create();
+        $this->assertInstanceOf(BelongsTo::class, $customerLog->customerLogStatus());
+    }
+}