Estoy intentando agregar un cliente a mi base de datos llenando un formulario y cuando lo agrego me tira el siguiente error. Estoy usando Laravel 7 y MySQL como base de datos, no sé si es de ayuda pero lo aclaro por las dudas.
'Class 'App\Customer' not found'
Esta es la migration: create_customers_table.php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateCustomersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('customers', function (Blueprint $table) {
$table->id();
$table->string('holding');
$table->string('company')->nullable();
$table->string('legal_entity')->nullable();
$table->string('email');
$table->string('country')->nullable();
$table->string('state')->nullable();
$table->string('city')->nullable();
$table->string('address')->nullable();
$table->string('postal')->nullable();
$table->string('cuit');
$table->string('website')->nullable();
$table->tinyInteger('status')->default('1');
$table->integer('id_parentCompany')->nullable();
$table->integer('created_by')->nullable();
$table->integer('updated_by')->nullable();
$table->timestamps();
});
}
Mi modelo Customer:
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
class Customer extends Model
{
protected $fillable = ['holding','company','legal_entity','mobile_no','email','country','state','city','address','postal'
,'cuit','website','status'];
}
Y por ultimo el CustomerController:
namespace App\Http\Controllers\Backend;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Model\Product;
use App\Model\Supplier;
use App\Model\Unit;
use App\Model\Category;
use App\Model\Purchase;
use App\Model\Invoice;
use App\Model\InvoiceDetail;
use App\Model\Payment;
use App\Model\PaymentDetail;
use App\Model\Customer;
use Auth;
use Session;
use DB;
use PDF;
class CustomerController extends Controller
{
public function view(){
$allData = Customer::all();
return view('backend.customer.view-customer', compact('allData'));
}
public function add(){
return view('backend.customer.add-customer');
}
public function store(Request $request){
$customer = new Customer();
$customer->holding = $request->holding;
/*$customer->name = $request->name;*/
$customer->company = $request->company;
$customer->legal_entity = $request->legal_entity;
$customer->email = $request->email;
$customer->country = $request->country;
$customer->state = $request->state;
$customer->city = $request->city;
$customer->address = $request->address;
$customer->postal = $request->postal;
$customer->cuit = $request->cuit;
$customer->website = $request->website;
$customer->id_parentCompany = $request->id_parentCompany;
$customer->created_by = Auth::user()->id;
$customer->save();
Session::flash('success');
return redirect()->route('customers.view');
}
No entiendo porque salta ese error si en todo momento está incluyendo al modelo de customer, en todos los archivos. Si alguien tiene alguna idea y me puede guiar se lo agradezco. Cabe aclarar que en mi base de datos el registro se guarda pero al momento de mostrarlo en la vista de customers donde estaría el listado, salta el error.
view-customer.blade.php:
@extends('backend.layouts.master')
@section('content')
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper bg-white">
<!-- Content Header (Page header) -->
<div class="content-header">
<div class="container-fluid">
<div class="row mb-2">
<div class="col-sm-6">
</div><!-- /.col -->
<div class="col-sm-6">
<ol class="breadcrumb float-sm-right">
<li class="breadcrumb-item"><a href="{{ route('home') }}">Home</a></li>
<li class="breadcrumb-item active">Clientes</li>
</ol>
</div><!-- /.col -->
</div><!-- /.row -->
</div><!-- /.container-fluid -->
</div>
<!-- /.content-header -->
<!-- Main content -->
<section class="content">
<div class="container-fluid">
<!-- Main row -->
<div class="row">
<!-- Left col -->
<section class="col-md-12">
<!-- Custom tabs (Charts with tabs)-->
<div class="card" style="background-image: linear-gradient(200deg, #070525ce 1%, rgb(1, 0, 5)100%);">
<div class="card-header">
<h3 class="font-weight-light text-white">Clientes
<a class="btn bg-white float-right btn-sm" href="{{ route('customers.add') }}"><i class="fa fa-plus-circle mr-2"></i> Agregar Cliente</a>
</h3>
</div>
</div><!-- /.card-header -->
<div class="card-body">
<table id="example1" class="table table-striped table-responsive" style="width: 100%">
<thead style="font-size: 14px">
<tr>
<th style="display:none ">Codigo</th>
<th>Holding</th>
<th>Empresa</th>
<th>Razon Social</th>
<th>Telefono</th>
<th>Email</th>
<th>Pais</th>
<th>Provincia/Estado</th>
<th>Ciudad</th>
<th>Direccion</th>
<th>CP</th>
<th>Cuit</th>
<th>Website</th>
</tr>
</thead>
<tbody>
@foreach($allData as $key => $customer)
<tr>
<td style="display: none;">{{$key+1}}</td>
<td>{{$customer->parent->holding }}</td>
<td>{{$customer->company }}</td>
<td>{{$customer->legal_entity }}</td>
<td>{{$customer->mobile_no}}</td>
<td>{{$customer->email}}</td>
<td>{{$customer->country}}</td>
<td>{{$customer->state}}</td>
<td>{{$customer->city}}</td>
<td>{{$customer->address}}</td>
<td>{{$customer->postal }}</td>
<td>{{$customer->cuit}}</td>
<td>{{$customer->website}}</td>
<td>
<a title="Edit" class="btn btn-sm bg-gradient-yellow" href="{{ route('customers.detail', $customer->id) }}"><i
class="fa fa-eye"></i></a>
<a title="Edit" class="btn btn-sm text-white" style="background-image: linear-gradient(200deg, #070525ce 1%, rgb(1, 0, 5)100%);" href="{{ route('customers.edit', $customer->id) }}"><i
class="fa fa-edit"></i></a>
<a title="Delete" id="delete" class="btn btn-sm btn-danger" href="{{ route('customers.delete', $customer->id) }}"><i
class="fa fa-trash"></i></a>
</td>
</tr>
@endforeach
</tbody>
</table>
</div><!-- /.card-body -->
</div>
<!-- /.card -->
</section>
<!-- right col -->
</div>
<!-- /.row (main row) -->
</div><!-- /.container-fluid -->
</section>
<!-- /.content -->
</div>
<!-- /.content-wrapper -->
@endsection
<h1> {{ App\Customer }} </h1>
o similar.