Kaynağa Gözat

CustomerLog init

ANG YU 5 yıl önce
ebeveyn
işleme
560a12f370

+ 10 - 0
app/CustomerLog.php

@@ -0,0 +1,10 @@
+<?php
+
+namespace App;
+
+use Illuminate\Database\Eloquent\Model;
+
+class CustomerLog extends Model
+{
+    protected $fillable = ['customer_id', 'customer_log_status_id', 'user_id', 'description'];
+}

+ 59 - 0
app/Http/Controllers/CustomerLogsController.php

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

+ 9 - 0
database/factories/CustomerLogFactory.php

@@ -0,0 +1,9 @@
+<?php
+
+use Faker\Generator as Faker;
+
+$factory->define(App\CustomerLog::class, function (Faker $faker) {
+    return [
+        // 'name' => $faker->name,
+    ];
+});

+ 25 - 0
database/migrations/2020_12_14_101617_create_customerlogs_table.php

@@ -0,0 +1,25 @@
+<?php
+
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Support\Facades\Schema;
+
+class CreateCustomerLogsTable extends Migration
+{
+    public function up()
+    {
+        Schema::create('customer_logs', function (Blueprint $table) {
+            $table->increments('id');
+            $table->bigInteger('customer_id')->unsigned()->index();
+            $table->integer('customer_log_status_id')->unsigned()->index();
+            $table->bigInteger('user_id')->unsigned()->index();
+            $table->text('description');
+            $table->timestamps();
+        });
+    }
+
+    public function down()
+    {
+        Schema::drop('customer_logs');
+    }
+}

+ 20 - 0
database/seeds/CustomerLogsTableSeeder.php

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

+ 10 - 0
resources/views/common/error.blade.php

@@ -0,0 +1,10 @@
+@if (count($errors) > 0)
+  <div class="alert alert-danger">
+    <div class="mt-2"><b>有错误发生:</b></div>
+    <ul class="mt-2 mb-2">
+      @foreach ($errors->all() as $error)
+      <li><i class="glyphicon glyphicon-remove"></i> {{ $error }}</li>
+      @endforeach
+    </ul>
+  </div>
+@endif

+ 60 - 0
resources/views/customer_logs/create_and_edit.blade.php

@@ -0,0 +1,60 @@
+@extends('layouts.app')
+
+@section('content')
+
+<div class="container">
+  <div class="col-md-10 offset-md-1">
+    <div class="card ">
+
+      <div class="card-header">
+        <h1>
+          CustomerLog /
+          @if($customer_log->id)
+            Edit #{{ $customer_log->id }}
+          @else
+            Create
+          @endif
+        </h1>
+      </div>
+
+      <div class="card-body">
+        @if($customer_log->id)
+          <form action="{{ route('customer_logs.update', $customer_log->id) }}" method="POST" accept-charset="UTF-8">
+          <input type="hidden" name="_method" value="PUT">
+        @else
+          <form action="{{ route('customer_logs.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="customer_id-field">Customer_id</label>
+                    <input class="form-control" type="text" name="customer_id" id="customer_id-field" value="{{ old('customer_id', $customer_log->customer_id ) }}" />
+                </div> 
+                <div class="form-group">
+                    <label for="customer_log_status_id-field">Customer_log_status_id</label>
+                    <input class="form-control" type="text" name="customer_log_status_id" id="customer_log_status_id-field" value="{{ old('customer_log_status_id', $customer_log->customer_log_status_id ) }}" />
+                </div> 
+                <div class="form-group">
+                    <label for="user_id-field">User_id</label>
+                    <input class="form-control" type="text" name="user_id" id="user_id-field" value="{{ old('user_id', $customer_log->user_id ) }}" />
+                </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->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_logs.index') }}"> <- Back</a>
+          </div>
+        </form>
+      </div>
+    </div>
+  </div>
+</div>
+
+@endsection

+ 61 - 0
resources/views/customer_logs/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>
+          CustomerLog
+          <a class="btn btn-success float-xs-right" href="{{ route('customer_logs.create') }}">Create</a>
+        </h1>
+      </div>
+
+      <div class="card-body">
+        @if($customer_logs->count())
+          <table class="table table-sm table-striped">
+            <thead>
+              <tr>
+                <th class="text-xs-center">#</th>
+                <th>Customer_id</th> <th>Customer_log_status_id</th> <th>User_id</th> <th>Description</th>
+                <th class="text-xs-right">OPTIONS</th>
+              </tr>
+            </thead>
+
+            <tbody>
+              @foreach($customer_logs as $customer_log)
+              <tr>
+                <td class="text-xs-center"><strong>{{$customer_log->id}}</strong></td>
+
+                <td>{{$customer_log->customer_id}}</td> <td>{{$customer_log->customer_log_status_id}}</td> <td>{{$customer_log->user_id}}</td> <td>{{$customer_log->description}}</td>
+
+                <td class="text-xs-right">
+                  <a class="btn btn-sm btn-primary" href="{{ route('customer_logs.show', $customer_log->id) }}">
+                    V
+                  </a>
+
+                  <a class="btn btn-sm btn-warning" href="{{ route('customer_logs.edit', $customer_log->id) }}">
+                    E
+                  </a>
+
+                  <form action="{{ route('customer_logs.destroy', $customer_log->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_logs->render() !!}
+        @else
+          <h3 class="text-xs-center alert alert-info">Empty!</h3>
+        @endif
+      </div>
+    </div>
+  </div>
+</div>
+
+@endsection

+ 45 - 0
resources/views/customer_logs/show.blade.php

@@ -0,0 +1,45 @@
+@extends('layouts.app')
+
+@section('content')
+
+<div class="container">
+  <div class="col-md-10 offset-md-1">
+    <div class="card ">
+      <div class="card-header">
+        <h1>CustomerLog / Show #{{ $customer_log->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_logs.index') }}"><- Back</a>
+            </div>
+            <div class="col-md-6">
+              <a class="btn btn-sm btn-warning float-right mt-1" href="{{ route('customer_logs.edit', $customer_log->id) }}">
+                Edit
+              </a>
+            </div>
+          </div>
+        </div>
+        <br>
+
+        <label>Customer_id</label>
+<p>
+	{{ $customer_log->customer_id }}
+</p> <label>Customer_log_status_id</label>
+<p>
+	{{ $customer_log->customer_log_status_id }}
+</p> <label>User_id</label>
+<p>
+	{{ $customer_log->user_id }}
+</p> <label>Description</label>
+<p>
+	{{ $customer_log->description }}
+</p>
+      </div>
+    </div>
+  </div>
+</div>
+
+@endsection

+ 2 - 0
routes/web.php

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