any help is appreciated :
**the database have the tables created and working fine : **
but the browser returns error (Trying to get property of non-object (View: )
The controller file is :
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Models\DocTracking;
use App\Models\User;
use Exception;
use Auth;
use PDF;
use QrCode;
use Carbon;
use Validator;
use Illuminate\Support\Facades\input;
class DocTrackingController extends Controller
{
public function __construct() {
$this->middleware('auth', ['only', 'getDashboard']);
}
public function index(Request $request,$id=null)
{
if(!Auth::check()){
return "Please Login";
}
if($id != null){
$userid= $id;
}
else {
$user_id= Auth::user()->id;
$selluser = User::find($user_id);
}
$data = DocTracking::all();
$data = array(
'name'=> $request->name,
'start_date' =>Carbon::parse( $request->start_date),
'end_date' =>Carbon::parse( $request->end_date),
'amount' => $request->amount,
'merchant_id'=> $user_id
);
/*
$doc_data = DocTracking::all();
$doc_data = response()->json($data);
$doc_data = json_encode($data);
return view('doctracking.doctracking' ,['selluser'=>$selluser, 'doc_data' => $doc_data]); // return view('doctracking.doctracking',compact('doctracking') );
}
public function add_doc(Request $request)
{
$validation = Validator::make($request->all(),[
'name'=> 'required',
'start_date'=> 'required',
'end_date'=> 'required',
'amount'=> 'required',
'select_file'=> 'required |image |mimes:jpeg,png,jpg,gif,svg |max:2048',
]);
$this->validate( $request, [
'name'=> 'required',
'start_date'=> 'required',
'end_date'=> 'required',
'amount'=> 'required',
'select_file'=> 'required |image |mimes:jpeg,png,jpg,gif,svg |max:2048',
]);
if ( $validation->passes())
{
$user_id= Auth::user()->id;
$image = time().'.'.$request->file('select_file')->getClientOrignalExtension();
$request->file('select_file')->move(public_path('images'), $image);
$file=$request->file('select_file');
$uploaded_file_path='';
if($file!=null) {
$destinationPath = 'images/docktracking/';
$uploaded=$file->move($destinationPath,$file->getClientOriginalName());
$image= $uploaded->getPathName();
$img_name= $file->getClientOriginalName();
}
$data = array(
'name'=> $request->name,
'start_date' =>Carbon::parse( $request->start_date),
'end_date' =>Carbon::parse( $request->end_date),
'amount' => $request->amount,
'merchant_id'=> $user_id,
'image' =>$img_name
);
$doc_data= DocTracking::create($data);
return response()->json($doc_data);
}
}
}
?>
The model file is :
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class DocTracking extends Model
{
protected $table = 'doctracking';
}
?>
the view file is :
@foreach ( (array)$doc_data as $data )
@endforeach
i think that if get the data then every thing will work fine
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire