Laravel - multiple images explode/implode - php

I have project with multiple images and it is all working fine. All I want is to have just one image in products.blade.php and all images on productshow.blade.php. So this is my ProductsController:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Product;
class ProductsController extends Controller
{
/**
* Display a listing of the resource.
*
* #return \Illuminate\Http\Response
*/
public function index()
{
$products = Product::all();
return view('products')->with('products', $products);
}
/**
* Show the form for creating a new resource.
*
* #return \Illuminate\Http\Response
*/
public function create()
{
return view('createprod');
}
/**
* Store a newly created resource in storage.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$input=$request->all();
$images=array();
if($files=$request->file('images')){
foreach($files as $file){
$name=$file->getClientOriginalName();
$file->move('storage/image',$name);
$images[]=$name;
}
}
/*Insert your data*/
Product::insert( [
'images'=> implode("|",$images),
'title' =>$input['title'],
//you can put other insertion here
]);
return redirect('/products');
}
/**
* Display the specified resource.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function show($id)
{
$product = Product::find($id);
return view('productshow')->with('product', $product);
}
/**
* Show the form for editing the specified resource.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
* #param \Illuminate\Http\Request $request
* #param int $id
* #return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
}
And this is my products.blade.php:
#extends('layouts.app')
#section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">All products
New product +</div>
<hr>
<div class="card-body">
#foreach($products as $product)
<h2>{{$product->title}}</h2>
#foreach (explode('|', $product->images) as $image)
<br>
<a class="image-popup-vertical-fit" href="/storage/image/{{$image}}">
<img src="/storage/image/{{$image}}" style="width:100%">
</a>
#endforeach
<br>
<hr style="border: 1.5px solid grey">
#endforeach
<small><?php echo now() ?></small>
</div>
</div>
</div>
</div>
</div>
#endsection
So in my products.blade.php all images are showing(explode) but I only need to show one image, for example first image. How can I do that? I'm not so good at multiple images. Please help! Thanks!

As you said you just wanted to display a first image from set.
In your products.blade.php instead of #foreach use -
#php $img = explode('|', $product->images); #endphp
Remove -
#foreach (explode('|', $product->images) as $image)
<br>
<a class="image-popup-vertical-fit" href="/storage/image/{{$image}}">
<img src="/storage/image/{{$image}}" style="width:100%">
</a>
#endforeach
And add
<img src="/storage/image/{{$img[0]}}" style="width:100%">

{{ explode('|', $product->images)[0] }}
However, I'd recommend taking a look at Laravel's ORM HasMany relationship when you have time.

It looks like you are saving multiple images in one column?
That's not good approach. make a new model of product images with product as foreign key and save images there and get using Relationship.
** For Now ** you can do this
#foreach($products as $product)
<h2>{{$product->title}}</h2>
<?php
$allImages=explode('|', $product->images)
?>
<br>
<a class="image-popup-vertical-fit" href="/storage/image/{{$allImages[0]->images}}">
<img src="/storage/image/{{$allImages[0]->images}}" style="width:100%">
</a>
<br>
<hr style="border: 1.5px solid grey">
#endforeach
after converting to array, get first index [0] of array instead of looping it.

Related

storage’s server IP address could not be found

in Laravel 8 i was tried to show pdf file uploaded in storage folder,
and i got storage’s server IP address could not be found.
i want to uploade pdf file and show it on browser without download it
i used controlle function store to upload and show function to show pdf file
<?php
namespace App\Http\Controllers;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\App;
use Illuminate\Http\Response;
use Illuminate\Http\Request;
use App\Models\User;
use App\Models\Pdf;
class PdfController extends Controller
{
/**
* Display a listing of the resource.
*
* #return \Illuminate\Http\Response
*/
protected function authenticated(Request $request, $user)
{
if ( $user->isAdmin() ) {// do your magic here
return redirect()->route('pdfs');
}
return redirect('/home');
}
public function __construct()
{
$this->middleware([
'auth:sanctum',
config('jetstream.auth_session'),
'verified'
])->except(['show']);
}
public function index()
{
$pdfs = Pdf::latest()->paginate(5);
return view('pdfs.index',compact('pdfs'))
->with('i', (request()->input('page', 1) - 1) * 5);
}
/**
* Show the form for creating a new resource.
*
* #return \Illuminate\Http\Response
*/
public function create()
{
return view('pdfs.create');
}
/**
* Store a newly created resource in storage.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$request->validate([
'file' => 'required|mimes:pdf|max:2048',
]);
$fileModel = new pdf();
$pdf = $request->file;
$fileName = time() .'.pdf';
$filePath = $pdf->storeAs('uploads', $fileName, 'public');
$fileModel->name = $fileName;
$fileModel->file ='/storage/' . $filePath;
$fileModel->save();
return redirect()->route('pdfs.index')
->with('success','File has been uploaded.')
->with('pdf', $fileName);
}
/**
* Display the specified resource.
*
* #param \App\Models\Pdf $pdf
* #return \Illuminate\Http\Response
*/
public function show($ip)
{
$fileModel = Pdf::find($ip);
return view('pdfs.show', compact('fileModel'));
}
/**
* Show the form for editing the specified resource.
*
* #param \App\Models\Pdf $pdf
* #return \Illuminate\Http\Response
*/
public function edit(Pdf $pdf)
{
//
}
/**
* Update the specified resource in storage.
*
* #param \Illuminate\Http\Request $request
* #param \App\Models\Pdf $pdf
* #return \Illuminate\Http\Response
*/
public function update(Request $request, Pdf $pdf)
{
//
}
/**
* Remove the specified resource from storage.
*
* #param \App\Models\Pdf $pdf
* #return \Illuminate\Http\Response
*/
public function destroy(Pdf $pdf)
{
$pdf->delete();
return redirect()->route('pdfs.index')
->with('success','PDF deleted successfully');
}
}
this is my controller
#extends('pdfs.layout')
#section('content')
<div class="row">
<div class="col-lg-12 margin-tb">
<div class="pull-left">
<h2> Show PDF</h2>
</div>
<div class="pull-right">
<a class="btn btn-primary" href="{{ route('pdfs.index') }}"> Back</a>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Name:</strong>
{{ $fileModel->name }}
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<iframe src="/{{ $fileModel->file }}" frameborder="0"></iframe>
</div>
</div>
</div>
#endsection
and this is show.blade.php

Laravel displays blank page after renaming a page

I renamed my index.blade.php file in my 'cluster' folder into overview.blade.php and all of a sudden cluster/overview displays a blank page. I renamed all my other methods pointing towards the page so I am not sure what is going wrong here. I think it has to do with renaming the index
EDIT: added the relevant code
VIEW
#extends('layouts.app')
#include('modal')
#section('content')
<body>
<div class="container">
<div class="row">
<div class="col-12">
<button class="button -dark center">
‹ Home
</button>
<a href="/cluster/create">
<button type="submit" class="button -green center float-right">Voeg cluster toe</button>
</a>
</div>
</div>
<table class="table">
<thead>
<tr>
<th scope="col"><strong>Cluster naam</strong></th>
<th scope="col"></th>
<th scope="col"></th>
</tr>
<tbody>
#foreach($departments as $department)
<tr>
<form action="{{route('deletecluster', $department->id)}}" method="post" id="submit-button">
<td>{{$department->name}}</td>
#csrf
<td><button type="button" class="btn btn-info" data-toggle="modal" data-target="#registration">Bewerken</button></td>
<td><button class="btn btn-danger" type="submit">Verwijderen</button></td>
</form>
</tr>
#endforeach
</tbody>
</table >
</div>
<script type="text/javascript">
$(document).ready(function() {
$('#submit-button').on('submit', function(e){
$('#registration').modal('show');
e.preventDefault();
});
});
</script>
</body>
#endsection
ROUTING
Route::get('/', function () {
return view('auth/login');
});
Route::resource('event', 'EventController');
Route::resource('cluster', 'ClusterController');
Route::get('calendar', 'EventController#calendar');
Route::get('export', 'EventController#export');
Route::get('user/create', 'UserController#create');
Route::get('user/edit/{id}', 'UserController#edit');
Route::get('cluster/edit/{id}', 'ClusterController#edit');
Route::get('user/settings', 'UserController#settings')->name('settings');
Route::post('user/store', 'UserController#store');
Route::post('user/employeeStore', 'UserController#employeeStore');
Route::post('user/store_settings', 'UserController#settingsStore');
Route::post('user/addShift', 'UserController#addShift');
Route::post('user/togglemail', 'UserController#toggleMail');
Route::get('user/overview', 'UserController#overview');
Route::get('cluster/overview', 'ClusterController#overview')->name('overview');
Route::post('user/delete{id}', 'UserController#deleteUser')->name('deleteuser');
Route::post('cluster/delete{id}','ClusterController#deleteCluster')->name('deletecluster');
Route::post('event/store', 'EventController#store');
Auth::routes();
Route::get('/home', 'HomeController#index')->name('home');
//Route::get('laravel-send-email', 'EmailController#sendMail');
Route::get('user/changepassword', 'UserController#changePassword');
Route::post('user/updatepassword', 'UserController#updatePassword')->name('updatepassword');
CONTROLLER
class ClusterController extends Controller
{
/**
* Display a listing of the resource.
*
* #return \Illuminate\Http\Response
*/
public function overview()
{
$departments = Department::all();
return view ('cluster.overview')->with('departments', $departments);
}
/**
* Show the form for creating a new resource.
*
* #return \Illuminate\Http\Response
*/
public function create()
{
$shift_types = shift_type::all();
return view('cluster.create')->with('shift_types', $shift_types);
}
/**
* Store a newly created resource in storage.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$department = new Department();
$department->name = $request->input('clustername');
$department->save();
$typeArray = explode(',', $request->input('types'));
foreach($typeArray as $type) {
$shift_type = new ShiftType();
$shift_type ->shift_name = $type;
$shift_type->save();
$department_shift_type = new DepartmentShiftType();
$department_shift_type->department_id = $department->id;
$department_shift_type->shift_type_id = $shift_type->id;
$department_shift_type->save();
}
return $department->id;
}
/**
* Display the specified resource.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function edit($id)
{
$departmentshift = DepartmentShiftType::findOrFail($id);
$departmentshifts = DepartmentShiftType::all();
$shifts = ShiftType::all();
$shift = ShiftType::findOrFail($id);
$shift_id = $departmentshift->shift_type_id;
$department = Department::findOrFail($id);
return view('cluster.edit')->with('department', $department)->with('departmentshift', $departmentshift)->with('shift_id', $shift_id)->with('departmentshifts', $departmentshifts)->with('shifts', $shifts)->with('shift', $shift );
}
/**
* Update the specified resource in storage.
*
* #param \Illuminate\Http\Request $request
* #param int $id
* #return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function deleteCluster($id)
{
$department = Department::findOrFail($id);
$department->delete();
return redirect('cluster.overview');
}
public function destroy($id)
{
//
}
}
Move this line:
Route::get('cluster/overview', 'ClusterController#overview')->name('overview');
above this one:
Route::resource('cluster', 'ClusterController');
Laravel thinks you are trying to call this route:
/cluster/{cluster}
public function show($id)
{
//
}
You can confirm this by adding some return value in the show method
public function show($id)
{
dd('foobar');
}

Why $post is not an object in the third code?

I started learning Laravel today and I've ran into a problem.
There are 3 seperated posts. Each one has titles and I made an other title too which should be in the url of the page of the posts, for example:
something.com/posts/post_three instead of posts/3
With the id version (posts/3) it worked perfectly, but I tried to change the code so it will go to posts/post_three, but I keep getting the following error:
Trying to get property 'created_at' of non-object (View:
C:\xampp\htdocs\lsapp\resources\views\posts\show.blade.php)
I have the following codes which I've changed something in:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Post;
class PostsController extends Controller
{
/**
* Display a listing of the resource.
*
* #return \Illuminate\Http\Response
*/
public function index()
{
$posts = Post::orderBy('urltitle', 'desc')->paginate(5);
return view('posts.index')->with('posts', $posts);
}
/**
* Show the form for creating a new resource.
*
* #return \Illuminate\Http\Response
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function show($urltitle)
{
$post = Post::find($urltitle);
return view('posts.show')->with('post', $post);
}
/**
* Show the form for editing the specified resource.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
* #param \Illuminate\Http\Request $request
* #param int $id
* #return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
}
-
#extends('pages.layouts.app')
#section('content')
<h1 style="text-align: center">Posts</h1>
#if(count($posts) > 0)
#foreach($posts as $post)
{{$post->urltitle}}
<div class="card" style="padding-top: 8px">
<div class="card-body">
<h3>{{$post->title}}</h3>
<small>Written on: {{$post->created_at}}</small>
</div>
</div>
#endforeach
<div style="justify-content: center; display: flex;">{{$posts->links()}}</div>
#else
<p>No posts found</p>
#endif
#endsection
-
And here is the code which can't "recognise" $post
#extends('pages.layouts.app')
#section('content')
<div class="jumbotron text-center">
Go Back
<h1>{{$post->title}}</h1>
<div>{{$post->body}}</div>
<hr>
<small>Written at {{$post->created_at}}</small>
</div>
#endsection
This is where the error occurs:
public function show($urltitle)
{
$post = Post::find($urltitle); // <----
return view('posts.show')->with('post', $post);
}
The find() method will check for a primmary key (id by default) that hold the given value, so this both sentences are equal:
$post = Post::find($id);
// equals to:
$post = Post::where('id', $id)->first();
but given the fact that you are passing the urltitle instead of the $id, you should use a more generic approach:
$post = Post::where('urltitle', $urltitle)->first();
Also, as #devon said, you should check if a value is returned:
$post = Post::where('urltitle', $urltitle)->first();
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
if( ! $post)
{
// do something
}
or throw an error if the query returns nothing:
$post = Post::where('urltitle', $urltitle)->firstOrFail();
^^^^^^^^^^^^^

Datatables in Laravel

I'm new to Laravel and I'm trying to implement Datatables into my project but it doesn't seem to work.
My app.blade.php :
<script type="text/javascript" src="https://cdn.datatables.net/v/dt/dt-1.10.16/af-2.2.2/b-1.5.1/datatables.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/dt-1.10.16/af-2.2.2/b-1.5.1/datatables.min.css"/>
My view where my target table is:
<div class="panel panel-success">
<div class="panel-heading">
<h3 class="panel-title">Liste des tickets Exporter</h3>
</div>
<div class="panel-body">
<table class="table table-striped table-bordered table-hovered" id="table">
<thead>
<tr>
<td>Objet</td>
<td>Urgence</td>
<td>Statut</td>
<td>Utilisateur</td>
<td>Actions</td>
</tr>
</thead>
#foreach ($tickets as $ticket)
<tbody>
<tr>
<td width="25%">{{ $ticket->message}}</td>
<td width="25%">{{ $ticket->urgence->niveau}}</td>
<td width="25%">{{ $ticket->statut}}</td>
<td width="25%">{{ $ticket->utilisateur->name}}</td>
<td style='white-space: nowrap'>
Voir
Supprimer
</td>
</tr>
#endforeach
</tbody>
</table>
{{ $tickets->render()}}
</div>
</div>
<script>
$(document).ready( function () {
$('#table').DataTable();
} );
</script>
Can you help me do so?
Edit : This is my TicketsController Code as required:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use DB;
use App\Tickets;
use Auth;
use Session;
use App\Gestion;
use Excel;
use App\assistance;
use Carbon\Carbon;
class TicketsController extends Controller
{
public function __construct()
{
$this->middleware('auth');
$this->middleware('admin')->only('voir');
}/**
* 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()
{
$urgences=DB::table('urgences')->pluck('niveau','id');
$assistances=DB::table('assistances')->pluck('level','id');
return view('tickets.creation',compact('urgences','assistances'));
}
/**
* Store a newly created resource in storage.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$data=$request->all();
$this->validate($request,[
'message'=>'required|min:8',
'urgence_id'=>'required',
'typeassistance'=>'required',
]);
$data=array_add($data,'utilisateur_id',Auth::user()->id);
Tickets::create($data);
Session::flash('message','Vous avez ouvert un nouveau ticket.');
return redirect('/home');
}
/**
* Show the form for editing the specified resource.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function edit($id)
{
}
/**
* Update the specified resource in storage.
*
* #param \Illuminate\Http\Request $request
* #param int $id
* #return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
public function voir($id)
{
$gestions=Gestion::where('ticket_id',$id)->get();
$assistances=DB::table('assistances')->pluck('level','id');
$tickets=Tickets::findOrFail($id);
if($tickets->statut=='nouveau'){
$tickets->statut='ouvert';
$tickets->save();
}
return view('tickets.show',compact('tickets','gestions','assistances'));
}
public function exportxls(){
$weeklyTickets = \App\Tickets::whereBetween('created_at', array(date("Y-m-d", strtotime("-7 days")), date('Y-m-d')))->get();
Excel::create('tickets', function($excel) use ($weeklyTickets){
$excel->sheet('tickets', function($sheet) use ($weeklyTickets){
$sheet->loadView('export.ticketsexcel', array('weeklyTickets' => $weeklyTickets));
})->export('xls');
});
return redirect('/');
}
public function delete($id)
{
$tickets=Tickets::findOrFail($id);
$tickets->delete();
Session::flash('message','Vous avez bien supprimé le ticket.');
return redirect('/');
}
}
I would like my tables to be like the basic Datatables style, with the search bar. The search bar is a must for me, someone actually told me to use Datatables because i needed an instant search bar, I don't really mind the other parts of Datatables.
Thanks in advance.

Undefined variable of view in laravel 5.4

I define a variable in view. But problem is that it shows undefined. My task is, first i take all the input from user using form helper then i want to post it to the store function & do some calculation and then pass it to the view for showing purpose. But i tried it, unfortunately shows undefined.Undefined variable is "totalamount" Here i attached all the code:
controller:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\TestSetup;
use Illuminate\Support\Facades\Input;
class TestRequestController 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()
{
$allTestNames=TestSetup::all()->pluck('test_name','id');
// $testNames=TestSetup::orderBy('test_name')
// ->get();
return view('testrequestentries.createTestRequestEntry')->withAlltestnames($allTestNames);
// return view('testrequestentries.createTestRequestEntry');
}
/**
* Store a newly created resource in storage.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\Response
*/
public function store(Request $request)
{
// if(Input::get('Add')) {
$total=$request->fee+$total;
return view('testrequestentries.createTestRequestEntry')->withTotalamount($total);
// }else if(Input::get('Save')){
//
// }
}
/**
* Display the specified resource.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
* #param \Illuminate\Http\Request $request
* #param int $id
* #return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
}
view
#extends ('main')
#section('title','|Test Request Entry')
#section('stylesheets')
{!! Html:: style('css/parsley.css')!!}
#endsection
#section('content')
{!! Form::open(['route' => 'testrequests.store','data-parsley-validate'=>'']) !!}
{{Form::label('patient_name','Name of the Patient:')}}
{{Form::text('patient_name',null,array('class' => 'form-control','required'=>'', 'data-parsley-required-message' => 'Patient Name is required'))}}
{{Form::label('date_of_birth','Date Of Birth:')}}
{{Form::date('date_of_birth',null,array('class' => 'form-control','data-parsley-required' =>'true')) }}
{{Form::label('mobile_no','Mobile No:')}}
{{Form::text('mobile_no',null,array('class' => 'form-control','type'=> 'number','maxlength'=>'11','minlength' => '11','required'=>'', 'data-parsley-required-message' => 'Mobile No is required'))}}
{{Form::label('test_id','Select Test:')}}
{{Form::select('test_id',$alltestnames,null,['class'=>'form-control','required'=>'','placeholder' => 'Pick a Test...'])}}
{{Form::label('fee','Fee:')}}
{{Form::text('fee',null,array('class' => 'form-control','required'=>'', 'data-parsley-required-message' => 'Fee is required'))}}
{{Form::submit('Add',array('class' => 'btn btn-lg btn-block btn-success','style' => 'margin-top:10px;'))}}
<table class="table table-bordered" style="margin-top: 50px;">
<thead>
<tr>
<th>SL</th>
<th>Test Name</th>
<th>Fee</th>
<th>Type Name</th>
</tr>
</thead>
#php ($i=1)
<tbody>
<tr>
<th scope="row">{{$i}}</th>
<td>{{$totalamount}}</td>
</tr>
</tbody>
#php ($i++)
</table>
{!! Form::close() !!}
#section('scripts')
{!! Html:: script('js/parsley.min.js') !!}
#endsection
#endsection
I bet the view is returned from create() here, so change this:
return view('testrequestentries.createTestRequestEntry')->withAlltestnames($allTestNames);
To:
return view('testrequestentries.createTestRequestEntry', [
'alltestnames' => $allTestNames,
'totalamount' => $total
]);
In the store() method, do not return the view. Redirect back() or to index() or show() methods instead.
first thing first: check the value of $total=$request->fee+$total;
ie: put "dd('$total', $total);" right after the line you set it, before the return.
second: make it simplier return view(...)->with('totalAmount', $total);
test the value of $totalAmount in the view (BLADE file)
ie: {{dump('totalAmount', $totalAmount)}}
Anyway the store() method does NOT store anything ... WHY THAT?

Categories