SQLSTATE[23000]: Integrity constraint violation: 4025 CONSTRAINT `notes.file` failed for `classroom`.`notes` (SQL: insert into `notes` - laravel

I am getting this error in laravel 8
SQLSTATE[23000]: Integrity constraint violation: 4025 CONSTRAINT notes.file failed for classroom.notes (SQL: insert into notes (classroom_id, user_id, title, description, file, status, code, updated_at, created_at) values (3, 3, tes, teset, G:\xampp\tmp\php87A.tmp|G:\xampp\tmp\php87B.tmp|G:\xampp\tmp\php88B.tmp|G:\xampp\tmp\php88C.tmp|notes/270584134_3084881908463864_7790143535087104689_n.jpg_d645920e395fedad7bbbed0eca3fe2e0.jpg|notes/271593123_1376415469456519_8005701171651680985_n.jpg_812b4ba287f5ee0bc9d43bbf5bbe87fb.jpg|notes/272092182_232722372382525_5526411493206144373_n.jpg_f457c545a9ded88f18ecee47145a72c0.jpg|notes/AAYUAQR3AAgAAQAAAAAAADzjqItE3P0yRQGwRg-HnEHXKQ.png_f457c545a9ded88f18ecee47145a72c0.png, 1, ZkF7yZhckH, 2022-02-16 09:40:08, 2022-02-16 09:40:08))
This is the form
<form method="POST" action="{{url('class/note/')}}" enctype="multipart/form-data">
{{ csrf_field() }}
<div class="input-field">
<textarea id="title" name="title" class=" #error('title') is-invalid #enderror materialize-textarea validate"></textarea>
<label for="title">Note title</label>
</div>
<div class="input-field">
<textarea id="desc" name="description" class=" #error('desc') is-invalid #enderror materialize-textarea validate"></textarea>
<label for="desc">Note description</label>
</div>
<div class="input-field">
<p>Attach Files *</p>
<input type="file" class="filepond"
name="files[]" multiple />
</div>
<div class="input-field pb-5">
<input type="hidden" name="cid" value="{{ $classroom->id }}">
<button onclick="submitBtn()" id="working" class="btn waves-effect waves-light comment right" type="submit" name="action">Submit
<i class="material-icons right">send</i>
</button>
<script>
function submitBtn() {
document.getElementById('working').innerText = 'Please wait...';
};
</script>
</form>
This is the controller
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
use App\Models\classroom;
use App\Models\post;
use App\Models\comment;
use App\Models\note;
use Auth;
class noteController extends Controller
{
/**
* Create a new controller instance.
*
* #return void
*/
public function __construct()
{
$this->middleware('auth');
}
public function store(Request $request)
{
$this->validate($request,[
'files' => 'required',
]);
$note = new note;
$user = Auth::user();
$randoml = Str::random(10);
$note->classroom_id = $request->input('cid');
$note->user_id = $user->id;
$note->title = $request->input('title');
$note->description = $request->input('description');
$files = array();
if($files = $request->file('files')){
foreach($files as $file){
$filename = $file->getClientOriginalname().'_' . md5(rand(10, 100)) .'.'. $file->getClientOriginalExtension();
$path = 'notes/';
$url = $path.$filename;
$file->move($path, $filename);
$files[] = $url;
$note->file = implode('|', $files);
}
}
$note->status = 1;
$note->code = $randoml;
$note->save();
return redirect()->back()->with('success', 'Note posted');
}
}

i think your file name length more than database column's valid length

You are trying to store file on every iteration. you should store the paths in an array as you have done but only store the file after every iteration is performed and path is stored in your $files[] array but laravel has simple image upload api here you can check this

Related

How can I save records in attendance table using Laravel?

I am having issue with saving attendance record of student in attendance listings. The frontend part is working well but record saved in backend of attendance table is not shown. How can I save record in backend table of attendance which consists of level_id, teacher_id and student_id
Here is my attendance migrations table
$table->id();
$table->unsignedBigInteger('level_id');
$table->unsignedBigInteger('teacher_id');
$table->unsignedBigInteger('student_id');
$table->foreign('level_id')->references('id')->on('levels');
$table->foreign('teacher_id')->references('id')->on('teachers');
$table->foreign('student_id')->references('id')->on('students');
$table->date('attendance_date');
$table->string('attendance_status');
$table->timestamps();
Here is my students migrations tables
$table->id();
// The Parents table must exist and Must have 'id' as Primary Key
$table->unsignedbiginteger('parent_id');
$table->unsignedbiginteger('level_id');
$table->foreign('parent_id')->references('id')->on('parents')
->onDelete('cascade');
$table->foreign('level_id')->references('id')->on('levels');
$table->string('student_roll_no');
$table->string('student_surname');
$table->string('student_middle_name')->nullable();
$table->string('student_given_name');
$table->string('student_place_of_birth');
$table->date('student_date_of_birth');
$table->string('student_gender');
$table->text('student_home_address');
$table->string('student_suburb')->nullable();
$table->string('student_post_code');
$table->string('student_home_phone')->nullable();
$table->string('student_work_phone')->nullable();
$table->string('student_mobile_phone');
$table->string('student_email')->nullable();
$table->string('student_photo')->nullable();
$table->string('language_spoken_at_home')->nullable();
$table->string('school_name');
$table->string('student_semester')->nullable();
$table->string('school_suburb')->nullable();
$table->text('school_address')->nullable();
$table->string('student_oversea_full_paying')->nullable();
$table->string('emergency_person_one_name')->nullable();
$table->string('emergency_person_one_mobile_number');
$table->string('emergency_person_one_house_number')->nullable();
$table->string('emergency_person_two_name')->nullable();
$table->string('emergency_person_two_mobile_number')->nullable();
$table->string('emergency_person_two_house_number')->nullable();
$table->string('medical_condition')->nullable();
$table->boolean('medical_health_support')->nullable();
$table->boolean('family_court_orders');
$table->string('family_court_file')->nullable();
$table->boolean('authority_to_school_staff');
$table->boolean('authorize_school_staff_to_arrange_medical_treatment');
$table->boolean('authorize_school_staff_administering_medication');
$table->boolean('notify_the_school_absent');
$table->boolean('withdraw_child_from_school');
$table->boolean('authorize_photograph_to_school');
$table->boolean('authorize_child_name_school_newsletter_website');
$table->boolean('authorize_short_local_walks');
$table->boolean('authorize_participate_in_any_incursions');
$table->boolean('information_contained_in_this_form_correct');
$table->boolean('status')->default(1);
$table->timestamps();
Here is my levels tables
$table->bigIncrements('id');
$table->string('level_name');
$table->timestamps();
Here is my Teachers migrations tables
$table->id();
// The Parents table must exist and Must have 'id' as Primary Key
$table->unsignedbiginteger('user_id')->nullable();
$table->foreign('user_id')->references('id')->on('users');
$table->string('teacher_name');
$table->string('teacher_email')->unique();
$table->string('teacher_home_phone')->nullable();
$table->string('teacher_mobile_phone');
$table->string('teacher_work_phone')->nullable();
$table->string('teacher_home_address');
$table->string('teacher_suburb')->nullable();
$table->string('teacher_postcode');
$table->timestamps();
Here is my Attendance Controller
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Models\Levels;
use App\Models\Teacher;
use App\Models\Student;
use App\Models\Attendance;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class AttendanceController extends Controller
{
/**
* Create a new controller instance
*
* #return void
*/
public function __construct()
{
$this->middleware('auth');
}
/**
* Show the application dashboard
*
* #return \Illuminate\Contracts\Support\Renderable
*/
public function index($level_id = NULL)
{
$levels = Levels::all();
$students = Student::all();
return view('admin.attendance.list', compact( 'levels', 'students','level_id'));
}
/**
* Perform Actions in attendance.add
*
* #return \Illuminate\Contracts\Support\Renderable
*/
public function add()
{
$levels = array();
$students = array();
return view('admin.attendance.add', compact('levels', 'teachers'));
}
/**
* Store values in application dashboard
*
* #return \Illuminate\Contracts\Support\Renderable
*/
public function store(Request $request, $level_id)
{
//get form data
$data = $request->all();
//Creeate Student record
$students = Student::all();
$levels = Levels::all();
if($level_id){
$levels = Levels::find($level_id);
if($levels){
$attendance = Attendance::with(['student', 'levels'])->first();
return view('admin.attendance.add', compact('students','level_id', 'levels', 'attendance'));
}
}
}
}
Here is my Attendance model
public function student()
{
return $this->belongsTo(Student::class,'student_id');
}
public function teacher()
{
return $this->belongsTo(Teacher::class, 'teacher_id');
}
public function levels()
{
return $this->belongsTo(Levels::class, 'level_id');
}
Here is my list.blade.php file of containing attendance
#section('content')
#if(session()->has('message'))
<div class="row">
<div class="col-md-12">
<div class="alert alert-success">
{{ session()->get('message') }}
</div>
</div>
</div>
#endif
#if(isset($levels) || $levels == '')
<div class="form-row justify-content-center">
<div class="form-group col-xs-6">
<label for="Date"> Please Select Date</label>
<input type="date" name="attendance_date" value="{{ date('Y-m-d') }}" class="form-control" required>
</div>
<div class="form-group col-xs-6">
<label for="Attendance">Please Select Level to see registered students</label>
<select class="form-control" id="level_id" name="student_id">
<option value="" disabled selected>Select Level</option>
#foreach($levels as $level)
<option value="{{#$level->id}}">{{#$level->level_name}}</option>
#endforeach
</select>
</div>
</div>
#endif
#stop
#section('js')
<script>
jQuery(document).ready(function($) {
// get your select element and listen for a change event on it
$('#level_id').change(function() {
// set the window's location property to the value of the option the user has selected
window.location = '/attendance/add/'+$(this).val();
});
});
</script>
#endsection
Here is my add.blade.php file containing attendance
<form action="{{ route('attendance.index') }}" method="GET" class="w-full max-w-xl px-6 py-12" enctype="multipart/form-data">
#csrf
#php
$heads = [
'Name',
'Roll Number',
'Semester',
['label' => 'Attendance', 'no-export' => true, 'width' => 5],
];
/*$btnDetails = '<button class="btn btn-xs btn-default text-teal mx-1 shadow" title="Details">
<i class="fa fa-lg fa-fw fa-eye"></i>
</button>';*/
$config = [
'data' => $students,
'order' => [[1, 'asc']],
'columns' => [null, null, null, null, ['orderable' => true]],
];
#endphp
{{-- Minimal example / fill data using the component slot --}}
<x-adminlte-datatable id="table6" :heads="$heads" head-theme="light" theme="light custom-head-theme dt-responsive"
striped>
#if($config['data'])
#foreach($config['data'] as $row)
<tr class="{{ (isset($row['status']) && $row['status']==0) ? 'table-danger' : ''}}">
<td>{!! $row['student_given_name'] !!}</td>
<td>{!! $row['student_roll_no']!!}</td>
<td>{!! $row['student_semester']!!}</td>
<td>
<nobr>
<select class="form-control" name="attendance_status" value="{{old('attendance_status'), #$attendance->attendance_status}}" id="attendance_status" required>
<option value="" {{#$attendance->attendance_status == '' ? 'selected' : ''}} disabled selected>Select Option</option>
<option value="Present" {{#$attendance->attendance_status == 'present' ? 'selected' : ''}} selected>Present</option>
<option value="Absent" {{#$attendance->attendance_status == 'absent' ? 'selected' : ''}}>Absent</option>
</select>
<input type="text" name="textinput" id="level_id" placeholder="Reason">
</nobr>
</td>
</tr>
#endforeach
#endif
</x-adminlte-datatable>
<div class="row mt-3">
<div class="col-md-12">
<div class="card-footer">
<div class="float-left col-md-4 mb-2">
<button type="submit" name="save_close" value="true" class="btn btn-primary btn-lg btn-block">Save & Close</button>
</div>
<div class="float-right col-md-4 mb-2">
<button type="button" class="btn btn-secondary btn-lg btn-block">Cancel</button>
</div>
</div>
</div>
</div>
</form>
#stop
What modifications are required in attendance controller in order to save record in table and I can view it on frontend side as well
On your AttendanceController you just show data, not insert data to database, you should get the request data and insert data to database, but first check your blade file, you must make an input for level_id, teacher_id, and student_id
to check your attachment you can use
dd($request);
die();
on your first line AttendanceController function store
public function store(Request $request, $level_id)
{
dd($request);
die();
//get form data
$data = $request->all();
//Create Student record
$students = Student::all();
$levels = Levels::all();
if($level_id){
$levels = Levels::find($level_id);
if($levels){
$attendance = Attendance::with(['student', 'levels'])->first();
return view('admin.attendance.add', compact('students','level_id', 'levels', 'attendance'));
}
}
}
if your system catch the good request
you should try this
public function store(Request $request, $level_id)
{
$levels_id = $request->level_id;
$teachers_id = $request->teacher_id;
$students_id = $request->student_id;
$data = [$levels_id,teachers_id,students_id];
attendance::create($data);
}
there's the code to save data into your laravel project, you should approve my solution

Field 'album_id' doesn't have a default value

I want to create a photo album using laravel version 8.9.0
I have created an album, when I click on an album I will go to the gallery view, when I upload a photo an error occurs like this
General error: 1364 Field 'album_id' doesn't have a default value (SQL: insert into galeris (deskripsi, user_id, image, updated_at, created_at) values (asa, 1, 1604133200.png, 2020-10-31 08:33:20, 2020-10-31 08:33:20))
create_galeris_table.php
public function up()
{
Schema::create('galeris', function (Blueprint $table) {
$table->increments('id')->unsigned();
$table->integer('user_id');
$table->integer('album_id')->unsigned();
$table->string('image');
$table->text('deskripsi');
$table->foreign('album_id')->references('id')->on('albums')->onDelete('CASCADE')->onUpdate('CASCADE');
$table->timestamps();
});
}
GaleriController.php
public function store(Request $request)
{
$request->validate([
'deskripsi' => 'required',
'image' => 'required|image|mimes:jpg,jpeg,png|max:2000',
]);
$galeri = New Galeri;
$galeri->deskripsi = $request->deskripsi;
$galeri->user_id = auth()->id();
if ($request->hasFile('image')) {
$file = $request->file('image');
$fileName = time().'.'.$file->getClientOriginalExtension();
$destinationPath = public_path('images/galeri');
$file->move($destinationPath, $fileName);
$galeri->image = $fileName;
}
$galeri->save();
return back()->with(['success' => 'Data Berhasil Disimpan!']);
}
galeri.blade.php
<div class="modal fade" id="uploadImage" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body">
<form action="{{route('galeri.store')}}" method="post" enctype="multipart/form-data">
#csrf
<div class="form-group">
<input type="file" name="image" class="form-control" style="padding-top: 3px;">
</div>
<div class="form-group">
<textarea name="deskripsi" class="form-control" placeholder="Deskripsi"></textarea>
</div>
<button type="submit" class="btn btn-success btn-block">Save</button>
</form>
</div>
</div>
</div>
</div>
Because in create_galeris_table.php migration file album_id field is not nullable or has a default value and in your GaleriController.php you are not inserting a value for album_id
So you could make album_id nullable in your migration file
$table->integer('album_id')->unsigned()->nullable();
Or insert a value for album_id while creating a new gallery record, so in store method you will add
public function store(Request $request)
{
$request->validate([
'deskripsi' => 'required',
'image' => 'required|image|mimes:jpg,jpeg,png|max:2000',
]);
$galeri = New Galeri;
$galeri->deskripsi = $request->deskripsi;
$galeri->user_id = auth()->id();
$album = Album::find('some-id'); // this id of the album you want to add to this gallery
$galeri->album_id = $album->id;
if ($request->hasFile('image')) {
$file = $request->file('image');
$fileName = time().'.'.$file->getClientOriginalExtension();
$destinationPath = public_path('images/galeri');
$file->move($destinationPath, $fileName);
$galeri->image = $fileName;
}
$galeri->save();
return back()->with(['success' => 'Data Berhasil Disimpan!']);
}

SQLSTATE[HY000]: General error: 1364 Field 'title' doesn't have a default value

Hi I am trying to insert data into db but it says:
SQLSTATE[HY000]: General error: 1364 Field 'title' doesn't have a
default value (SQL: insert into projects (owner_id, updated_at,
created_at) values (1, 2019-06-28 13:17:11, 2019-06-28 13:17:11))
I am following Laracasts Laravel from scratch tutorial
controller:
public function store()
{
$attributes = $this->validateProject();
$attributes['owner_id'] = auth()->id();
$project = Project::create($attributes);
//Project::create($attributes);
//Project::create(request(['title', 'description']));
Mail::to($project->owner->email)->send(
new ProjectCreated($project)
);
return redirect('/projects');
}
model:
protected $guarded = [];
table:
Schema::create('projects', function (Blueprint $table) {
$table->increments('id');
$table->unsignedInteger('owner_id');
$table->string('title');
$table->text('description');
$table->timestamps();
$table->foreign('owner_id')->references('id')->on('users')->onDelete('cascade');
});
blade file:
<form method="POST" action="/projects">
#csrf
<div class="field">
<label class="label" for="title">Title</label>
<div class="control">
<input type="text" class="input {{ $errors->has('title') ? 'is-danger' : ''}}" name="title" value="{{ old('title') }}" placeholder="Project title">
</div>
</div>
<div class="field">
<label class="label" for="title">Description</label>
<div class="control">
<textarea name="description" class="textarea {{ $errors->has('description') ? 'is-danger' : ''}}" placeholder="Project description">{{ old('description') }}</textarea>
</div>
</div>
<div class="field">
<div class="control">
<button type="submit" class="button is-link">Create Project</button>
</div>
</div>
#include('errors')
</form>
how to solve this issue
You have the field title on the projects table however you are not assigning it a value. As it is set as Not Nullable this will give this error.
You will need all attributes to be in the $fillable attribute on the model when using Project::create($attributes); which you do not seem to have.
An example of the $fillable would be :
protected $fillable = [
'title',
'description',
'owner_id',
];
There are several other potential causes however it is impossible to tell without you including your full Project model and the view which this request is from.
Edit
You will need to change your function to this :
public function store(ProjectRequest $request)
{
$attributes = $request->all();
$attributes['owner_id'] = auth()->id();
$project = Project::create($attributes);
Mail::to($project->owner->email)->send(
new ProjectCreated($project)
);
return redirect('/projects');
}
You can create the ProjectRequest class by running php artisan make:request ProjectRequest and then putting your validation rules in there instead.
Read more here.
Add your column name in fillable like this in your model (I guess your model name is Project.php)
So your model class should like this.
<?php
mnamespace App;
use Illuminate\Database\Eloquent\Model;
class Project extends Model
{
protected $guarded = [];
protected $fillable = [
'title', 'owner_id','description'
];
public function owner()
{
return $this->belongsTo(User::class);
}
public function tasks()
{
return $this->hasMany(Task::class);
}
public function addTask($task)
{
$this->tasks()->create($task);
}
}
And then update your controller store method like this.
public function store(Request $request)
{
$attributes = $this->validateProject();
$attributes->owner_id = auth()->id();
$attributes->title = $this->request->title;
$attributes->description= $this->request->description;
$project = Project::create($attributes);
Mail::to($project->owner->email)->send(
new ProjectCreated($project)
);
return redirect('/projects');
}
The error itself is self explanatory, check this code:
$attributes['owner_id'] = auth()->id();
$project = Project::create($attributes);
here you are creating a new record in project table, and for that you are taking only one column i.e. owner_id, but in the table there is a column title which do not have a default value.
So either take all the column while creating a new record or provide those column a default value (null or something else).
To set null as default value in migration:
$table->string('title')->nullable();
or you can directly change the column in database and set its default value as null, see the below screenshot:
Unable to trace the problem you are facing. Give this code a try and please comment if you got any problem.
Inside your route file
Route::post('project', 'ProjectController#store')->name('project.store');
In your create view
<form method="POST" action="{{route('project.store')}}">
#csrf
<div class="field">
<label class="label" for="title">Title</label>
<div class="control">
<input type="text" class="input {{ $errors->has('title') ? 'is-danger' : ''}}" name="title"
value="{{ old('title') }}" placeholder="Project title">
</div>
</div>
...
<div class="field">
<div class="control">
<button type="submit" class="button is-link">Create Project</button>
</div>
</div>
#include('errors')
</form>
In your ProjectController
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Post;
class UserController extends Controller{
public function store(Request $request)
{
$this->validate($request, [
'title' => 'required|max:255',
]);
$post = Post::create([
'title' => $request->title,
'owner_id' => auth()->id()
]);
return redirect('/projects');
}
EDIT 1
In your previous code inside ProjectsController, instead of using $attributes try using
public function store()
{
$project = Project::create([
'title' => request('title'),
'owner_id' => request('owner_id')
]);
Mail::to($project->owner->email)->send(
new ProjectCreated($project)
);
return redirect('/projects');
}
EDIT 2
Instead of using create method, try this one
public function store()
{
$project = new Project();
$project->title = request('title');
$project->owner_id = request('owner_id');
$project->save();
...
}

DOMPDF - Laravel - Email PDF with Attachment

I am getting this error what would be the reason for this
"Undefined variable: quotation"
QuotationController.php
public function update(Request $request, Quotation $quotation)
{
{
$quotation->description= $request['description'];
$quotation->qty= $request['qty'];
$quotation->each_price= $request['each_price'];
$quotation->save();
$info = ['info'=>$quotation];
Mail::send(['text'=>'mail'], $info, function($message){
$pdf = PDF::loadView('employees.quotations.edit', $quotation);
$message->to('example#gmail.com','John Doe')->subject('Quotation');
$message->from('from#gmail.com','The Sender');
$message->attachData($pdf->output(), 'filename.pdf');
});
echo 'Email was sent!';
}
}
public function edit(Quotation $quotation)
{
return view('employees.quotations.edit', compact('quotation'));
//return view('employees.quotations.edit')->with('quotation');
}
......................................................................
routes look like this
Route::post('/quotation', 'Employee\QuotationController#store')->name('employee.quotation.store');
Route::get('/quotation', 'Employee\QuotationController#index')->name('employee.quotation.index');
Route::get('/quotation/create', 'Employee\QuotationController#create')->name('employee.quotation.create');
Route::put('/quotation/{quotation}', 'Employee\QuotationController#update')->name('employee.quotation.update');
Route::get('/quotation/{quotation}', 'Employee\QuotationController#show')->name('employee.quotation.show');
Route::delete('/quotation/{quotation}', 'Employee\QuotationController#destroy')->name('employee.quotation.destroy');
Route::get('/quotation/{quotation}/edit', 'Employee\QuotationController#edit')->name('employee.quotation.edit');
employees.quotations.edit.blade.php looks like this
#section('left-menu')
#endsection
#section('right-menu')
#endsection
#section('content')
<h1>Update a Quotation</h1>
<br><br>
<form action="{{ route('employee.quotation.update',$quotation->id) }}" method="post">
#method('PUT')
#csrf
<div class="form-group">
<label for="inputJobDescription">Description</label>
<textarea class="form-control" rows="2" id="inputQuoteDescription" name="description" placeholder="Description">{{$quotation->description}}
</textarea>
</div>
<div class="form-group row">
<label for="inputQty" class="col-2 col-form-label">Qty</label>
<div class="col-10">
<input type="text" class="form-control" id="inputQty" name="qty" value="{{$quotation->qty}}" oninput="quotation_calculate()" onchange="quotation_calculate()">
</div>
</div>
<div class="form-group row">
<label for="inputEachPrice" class="col-2 col-form-label">Each Price</label>
<div class="col-10">
<input type="text" class="form-control" id="inputEachPrice" name="each_price" value="{{$quotation->each_price}}" oninput="quotation_calculate()" onchange="quotation_calculate()">
</div>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
#endsection
#section('pagescript')
#stop
What am i missing here ? I am already passing $quotation to the edit view
You are obviously not passing the $quotation variable through your route. You are also using the $quotation as an object; that tells me you don't intend passing it through the route. Try the following code:
public function update(Request $request, $quotation_id)
{
$quotation = Quotation::findOrFail($quotation_id);
$quotation->description= $request['description'];
$quotation->qty= $request['qty'];
$quotation->each_price= $request['each_price'];
$quotation->update();
$info = ['info'=>$quotation];
Mail::send(['text'=>'mail'], $info, function($message) use ($quotation){
$pdf = PDF::loadView('employees.quotations.edit', $quotation);
$message->to('example#gmail.com','John Doe')->subject('Quotation');
$message->from('from#gmail.com','The Sender');
$message->attachData($pdf->output(), 'filename.pdf');
});
echo 'Email was sent!';
}
This should work.
Why are you using double brackets to declare a function ? Why not:
public function update(Request $request, Quotation $quotation)
{
$quotation->description= $request['description'];
$quotation->qty= $request['qty'];
$quotation->each_price= $request['each_price'];
$quotation->save();
$info = ['info'=>$quotation];
Mail::send(['text'=>'mail'], $info, function($message){
$pdf = PDF::loadView('employees.quotations.edit', $quotation);
$message->to('example#gmail.com','John Doe')->subject('Quotation');
$message->from('from#gmail.com','The Sender');
$message->attachData($pdf->output(), 'filename.pdf');
});
echo 'Email was sent!';
}
I think you need to pass $quotation into the closure:
Mail::send(['text' => 'mail'], $info, function ($message) use ($quotation) {
$pdf = PDF::loadView('employees.quotations.edit', $quotation);
$message->to('example#gmail.com', 'John Doe')->subject('Quotation');
$message->from('from#gmail.com', 'The Sender');
$message->attachData($pdf->output(), 'filename.pdf');
});

I Cannot able to pass the id in route file in laravel

I am declaring the above thing in the route for edit of my data.
Route::get('editproduct/{id}', 'HomeController#Edit_Product');
Above is my editproduct.blade.php page
<?php
$id = $_GET['eid'];
$product_info = DB::select("SELECT * FROM `product` WHERE `pid` = '".$id."'");
foreach($product_info as $detail)
{
$actual_image = 'theme/uploads/'.$detail->pimage;
$product_image = $detail->pimage;
$product_name = $detail->pname;
$product_price = $detail->pprice;
}
?>
#include('include/header')
<div class="tab-pane add-product-view" id="profile">
<form name="add_product" method="post" enctype="multipart/form-data" role="form" action="{{ url('edit-product-process') }}">
{{ csrf_field() }}
<div class="form-label">Add Image: </div>
<div class="form-field"><input type="file" name="add_image" id="add_image" value="{{asset($actual_image)}}" /></div>
<img src="{{asset($actual_image)}}" width="50" height="50" />
<div class="form-label">Product Name:</div>
<div class="form-field"><input type="text" name="product_name" id="product_name" value="{{ $product_name }}" /></div>
<div class="form-label">Product Price:</div>
<div class="form-field"><input type="text" name="product_price" id="product_price" value="{{ $product_price }}" /></div>
<div class="btn btn-primary"><input type="submit" name="submit" value="Add Product"</div>
</form>
</div>
#include('include/footer')
This is My HomeController.blade.php
public function Edit_Product($id){
return View::make('editproduct')->with('id', $id);
}
public function edit_product_process(Request $request){
$prd_id = $request->pid;
$imageTempName = $request->file('add_image')->getPathname();
$imageName = $request->file('add_image')->getClientOriginalName();
$path = base_path() . '/theme/uploads/';
$request->file('add_image')->move($path , $imageName);
$remember_token = $request->_token;
$date = date('Y-m-d H:i:s');
$pname = $request->product_name;
$pprice = $request->product_price;
DB::table('product')->where('pid',$prd_id)->update(
array(
'pimage' => $imageName,
'pname' => $pname,
'pprice' => $pprice,
'remember_token' => $remember_token,
'created_at' => $date,
'updated_at' => $date,
)
);
return redirect('dashboard');
}
I am getting the below error, Please anyone can be able to help me, I am new at laravel.
page is not found
NotFoundHttpException in RouteCollection.php line 161:
If you're getting this error when you're trying to submit the form, you should check you route. It should look like this:
Route::post('edit-product-process', 'HomeController#edit_product_process');
Also, to pass an ID into edit_product_process you need to add field with ID into the form:
<input type="hidden" name="id" value="{{ $id }}">
And then you can get it in edit_product_process with $request->id
Your route should be as:
Route::get('editproduct/{id}', 'HomeController#Edit_Product')->name('product.edit');
Then you can use it as:
{{ route('product.edit', ['id' => $id]) }}
But it's a terrible practice to use DB queries in views.
Please do read more about queries and controllers in the docs.
Check Your Controller Name Why r using blade in that.This is bad practice.HomeController.blade.php

Resources