4,610 experience to go until the next level!
In case you were wondering, you earn Laracasts experience when you:
Earned once you have completed your first Laracasts lesson.
Earned once you have earned your first 1000 experience points.
Earned when you have been with Laracasts for 1 year.
Earned when you have been with Laracasts for 2 years.
Earned when you have been with Laracasts for 3 years.
Earned when you have been with Laracasts for 4 years.
Earned when you have been with Laracasts for 5 years.
Earned when at least one Laracasts series has been fully completed.
Earned after your first post on the Laracasts forum.
Earned once 100 Laracasts lessons have been completed.
Earned once you receive your first "Best Reply" award on the Laracasts forum.
Earned if you are a paying Laracasts subscriber.
Earned if you have a lifetime subscription to Laracasts.
Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.
Earned once you have achieved 500 forum replies.
Earned once your experience points passes 100,000.
Earned once your experience points hits 10,000.
Earned once 1000 Laracasts lessons have been completed.
Earned once your "Best Reply" award count is 100 or more.
Earned once your experience points passes 1 million.
Earned once your experience points ranks in the top 50 of all Laracasts users.
Replied to OnDelete('cascade) Not Working
@martal ok thank bro for helping. I may delete not more than 10 records so I will go through the events and listeners. So I am seeing the documentation now. I will try that one now If I got some errors I will let you know thank you once again
Replied to OnDelete('cascade) Not Working
@martal I am using MySQL and I want If I delete a parent record I want all child record should be deleted. How to do that one?
Started a new Conversation OnDelete('cascade) Not Working
Hi
I Have 3 tables
1)policy (primary key)
2)project_declaration (foreign key for policy)
3)endorsement (foreign key for policy)
when I delete a record in the policy table. The other records which are link to that table are not deleting. I am using onDelete('cascade) and I am using soft delete in all 3 tables.
my migration files
policies
Schema::create('policies', function (Blueprint $table) {
$table->bigIncrements('id');
$table->integer('controll_number');
$table->string('customer_name');
$table->string('insured_name');
$table->integer('policy_number');
$table->string('policy_type');
$table->date('start_date');
$table->date('end_date');
$table->string('insurance_company');
$table->string('policy_sum_insured');
$table->string('premium');
$table->string('gst');
$table->string('total_premium');
$table->timestamps();
});
project declaration
Schema::table('project_declerations', function (Blueprint $table) {
$table->unsignedBigInteger('policy_number_id')->after('id')->nullable();
$table->foreign('policy_number_id')->references('id')->on('policies')->onDelete('cascade');
$table->unsignedBigInteger('Brand_id')->after('contact_person')->nullable();
$table->foreign('Brand_id')->references('id')->on('brands')->onDelete('cascade');
$table->date('intimation_date')->after('addredd')->default(now());
});
endorsement
Schema::create('endorsements', function (Blueprint $table) {
$table->bigIncrements('id');
$table->unsignedBigInteger('legalentity');
$table->unsignedBigInteger('policy_number');
$table->string('location');
$table->string('premium');
$table->string('gst');
$table->string('totalpremium');
$table->date('start_date');
$table->date('end_date');
$table->string('suminsured');
$table->text('description');
$table->text('endorsement_filename');
$table->foreign('legalentity')->references('id')->on('legal_entities')->onDelete('cascade');
$table->foreign('policy_number')->references('id')->on('policies')->onDelete('cascade');
$table->timestamps();
});
Replied to Updating File Via Postman (returning Filename As Null)
@tykus yup it is working thank you very much
Started a new Conversation Updating File Via Postman (returning Filename As Null)
I am creating an API for updating the profile pic. while using postman I am getting null value when I use $request->file('filename)
my route
Route::put('/updatetudent/{id}','Api\[email protected]');
my controller
public function update(Request $request,$id)
{
$filename = $request->file('photo');
return response()->json(['filename' => $filename],200);
}
in postman my headers
1)Content-Type = multipart/form-data
2)Accept = application/json
3)Authorization = Bearer token
my output
{
"filename": null
}
Awarded Best Reply on Laravel GroupBy Query (API Resource)
@sinnbeck @bugsysha I have made changes like this
$exam_types = StudentsMark::whereIn('academic_id',$ids)->whereIn('student_id',$studentid)->distinct()->get(['exam_type','academic_id','student_id']);
$marks = StudentMarksResource::collection($exam_types);
resource file is
public function toArray($request)
{
return [
'exam_type' => $this->exam_type,
'details' => StudentMarks::where('academic_id', $this->academic_id)
->where('student_id', $this->student_id)
->where('exam_type',$this->exam_type)
->get(),
];
}
thank you once again
Replied to Laravel GroupBy Query (API Resource)
@sinnbeck @bugsysha I have made changes like this
$exam_types = StudentsMark::whereIn('academic_id',$ids)->whereIn('student_id',$studentid)->distinct()->get(['exam_type','academic_id','student_id']);
$marks = StudentMarksResource::collection($exam_types);
resource file is
public function toArray($request)
{
return [
'exam_type' => $this->exam_type,
'details' => StudentMarks::where('academic_id', $this->academic_id)
->where('student_id', $this->student_id)
->where('exam_type',$this->exam_type)
->get(),
];
}
thank you once again
Replied to Laravel GroupBy Query (API Resource)
Replied to Laravel GroupBy Query (API Resource)
@bugsysha I tried that one I am getting an error Call to undefined method stdClass::first()
$marks = DB::table('students_marks')
->whereIn('academic_id',$ids)
->whereIn('student_id',$studentid)
->get()
->map(function($group){
StudentMarksResource::collection($group);
})
->groupBy('exam_type');
Replied to Laravel GroupBy Query (API Resource)
Replied to Laravel GroupBy Query (API Resource)
@bugsysha thank for replying I will try this and let you know
Replied to Unable To Call Post Route In Form Tag
@sinnbeck yes you are right it is going to correct route after that it is redirecting from the controller.
it was a mistake in the controller. I was scratching my head from the last 2 hours.
@sinnbeck I have one more problem give me some idea about this https://laracasts.com/discuss/channels/laravel/laravel-groupby-query-api-resource
thank you so much
Replied to Unable To Call Post Route In Form Tag
@sinnbeck yes it is correct But is going to viewstudentmarks url
Started a new Conversation Unable To Call Post Route In Form Tag
Hi
When I click on the submit button it is not calling post method. Instead, it is calling some other URL
My form
<form method="post" style="padding-top:30px;" action="{{ route('updatestudentmark',['id' => $stuid]) }}">
{{csrf_field()}}
<input type="hidden" name="type" value="{{$examtype}}">
<div class="row text-center">
<div class="col-lg-12 col-md-12 col-sm-12">
<div class="row">
<div class="col-lg-12">
<div class="form-group">
<div class="row text-left">
<div class="col-sm-4 col-lg-12 col-md-4">
<table class="table">
<tr>
<th>Subjects</th>
<th>Marks Obtain</th>
<th>Grade</th>
</tr>
@foreach($mark as $mrk)
<tr>
<td><input type="text" class="form-control" name="subject[]" readonly value="{{$mrk->subject}}"></td>
<td><input type="number" name="marks[]" class="form-control" value="{{$mrk->marks}}"></td></td>
<td><input type="text" class="form-control" value="{{$mrk->marksgrade}}" disabled></td>
</tr>
@endforeach
@foreach($extra as $detail)
<tr>
<td>Total</td>
<td>{{$detail->total}}</td>
</tr>
<tr>
<td>Average Grade</td>
<td>{{$detail->grade}}</td>
</tr>
<tr>
<td>Percentage</td>
<td>{{$detail->percentage.' %'}}</td>
</tr>
@endforeach
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
{{-- @foreach($extra as $detail)
<a class="btn btn-success" href='{{ url("viewstudentmarks/{$detail->class_id}") }}'>Back</a>
@endforeach --}}
<input type="submit" class="btn btn-primary">
</form>
my route file
Route::post('updatestudentmark/{id}','[email protected]')->name('updatestudentmark');
Replied to Laravel GroupBy Query (API Resource)
@sinnbeck I have tried this also. how you have told me yesterday
``` $marks = DB::table('students_marks')
->whereIn('academic_id',$ids)
->whereIn('student_id',$studentid)
->get()->groupBy('exam_type')->map(function($group){
return StudentMarksResource::collection($group);
});```
Replied to Laravel GroupBy Query (API Resource)
@sinnbeck No that is for time table. that is working fine. This is for student marks, In this I am not getting the data in the above format
Started a new Conversation Laravel GroupBy Query (API Resource)
Hi
I am trying to get a student marks details that are group by exam_type. I need to create a API in below format. But I am unable to do that one. I need help with building query.
{
"success": true,
"data": [
{
"exam_type": "Annually",
"details":[
{
// all student marks details group by exam_type
"student_id": 89,
"subject": "English",
"marks": "50",
"marksgrade": "B",
"total": "300",
"grade": "B",
"percentage": "50",
"year": "2019"
},
{
// all student marks details group by exam_type
"student_id": 89,
"subject": "Mathematics",
"marks": "50",
"marksgrade": "B",
"total": "300",
"grade": "B",
"percentage": "50",
"year": "2019"
},
],
}
]
}
what I have tried
$marks = StudentMarksResource::collection(StudentsMark::whereIn('academic_id',$ids)
->whereIn('student_id',$studentid)->get()->groupBy('exam_type'));
Resource file
public function toArray($request)
{
return [
'exam_type' => $this->exam_type,
'class_id' => Course::find($this->class_id),
'batch_id' => Batch::find($this->batch_id),
'student_id' => Student::find($this->student_id),
'subject' => $this->subject,
'marks' => $this->marks,
'marksgrade' => $this->marksgrade,
'total' => $this->total,
'grade' => $this->grade,
'percentage' => $this->percentage,
'year' => $this->year,
];
}
how i am sending the data
return response()->json(['success' => true,'data' => $marks,'status' => 200]);
Replied to Property [academic_id] Does Not Exist On This Collection Instance
@sinnbeck thank you very very much it is working
Replied to Property [academic_id] Does Not Exist On This Collection Instance
@sinnbeck @bobbybouwmann I need to pass API that is group by Day
Replied to Property [academic_id] Does Not Exist On This Collection Instance
@sinnbeck yes If I remove groupBy it will work
Started a new Conversation Property [academic_id] Does Not Exist On This Collection Instance
Hi
I am using an API resource. I am getting this error in collection instance
$timetables = TimetableResource::collection(DB::table('time_tables')
->whereIn('academic_id', $ids)
->whereIn('class', $classid)->get()->groupBy('day'));
and my TimetableResource file
public function toArray($request)
{
return [
'academic_id' => $this->academic_id,
'day' => $this->day,
'class' => Course::find($this->class),
'subject' => Subject::find($this->subject),
'teacher' => Teacher::find($this->teacher),
'timeslot' => $this->timeslot
];
}
Awarded Best Reply on How To Change The Response Messages In Tymon JWT Package
solved
in app/Exceptions/Handler.php write the above code
public function render($request, Exception $exception)
{
if ($request->is('api/*') || $request->expectsJson() || $request->is('webhook/*')) {
if ($exception instanceof Tymon\JWTAuth\Exceptions\TokenInvalidException) {
return response()->json(['errors'=>'Invalid Token']);
}
}
return parent::render($request, $exception);
}```
Replied to How To Change The Response Messages In Tymon JWT Package
solved
in app/Exceptions/Handler.php write the above code
public function render($request, Exception $exception)
{
if ($request->is('api/*') || $request->expectsJson() || $request->is('webhook/*')) {
if ($exception instanceof Tymon\JWTAuth\Exceptions\TokenInvalidException) {
return response()->json(['errors'=>'Invalid Token']);
}
}
return parent::render($request, $exception);
}```
Started a new Conversation How To Change The Response Messages In Tymon JWT Package
Hi I want to change response messages in the Tymon JWT package. For example while fetching the data without using token I am getting this message
"message": "Token Signature could not be verified.",
"exception": "Tymon\JWTAuth\Exceptions\TokenInvalidException",
I want to change that response like instead of the message I need to pass errors
"errors": "Invalid token.",
`
Replied to How To Send JSON Response In Laravel
@nakov No, Now I will go through it thank you for your response
Started a new Conversation How To Send JSON Response In Laravel
Hi, I want to send a JSON response like where ever the Id is there I want to send their particular details.
example shown below
what I am getting
[
{
"id": 7,
"academic_id": 2,
"assignment_type": "Class Wise",
"subject": 4,
"batch": 1,
"course": 2,
}
]
How I want
[
{
"id": 7,
"academic_id": 2,
"assignment_type": "Class Wise",
"subject": {
"id":4,
"subjectname" : "Physic",
},
"batch": 1,
"course": {
"id":2,
"name" : "10th",
},
}
]
Replied to A Non-numeric Value Encountered Error In Maatwebsite While Importing
@fylzero thank you it is working now
Started a new Conversation A Non-numeric Value Encountered Error In Maatwebsite While Importing
my controller
public function import(Request $request)
{
Excel::import(new TeacherImport, $request->file('teacherimport'));
return redirect('/teachers')->with('success','Teacher Imported Successfully');
}
my import file
class TeacherImport implements ToModel
{
public function model(array $row)
{
$ids = Academic::select('id')->active()->first();
return new Teacher([
'academic_id' => $ids->id,
'first_name' => $row[0],
'last_name' => $row[1],
'email' => $row[2],
'mobile' => $row[3],
'qualification' => $row[4],
'dob' => \PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($row[5]),
'age' => $row[6],
'state' => $row[7],
'city' => $row[8],
'address' => $row[9]
]);
}
}
Replied to A Non-numeric Value Encountered
@fylzero I am posting a new question so you can understand
Replied to A Non-numeric Value Encountered
@fylzero ok this is mycontroller
public function import(Request $request)
{
Excel::import(new TeacherImport, $request->file('teacherimport'));
return redirect('/teachers')->with('success','Teacher Imported Successfully');
}
Replied to A Non-numeric Value Encountered
@fylzero hey mine is different this is my file
public function model(array $row)
{
$ids = Academic::select('id')->active()->first();
return new Teacher([
'academic_id' => $ids->id,
'first_name' => $row[0],
'last_name' => $row[1],
'email' => $row[2],
'mobile' => $row[3],
'qualification' => $row[4],
'dob' => \PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($row[5])->format('d-m-y'),
'age' => $row[6],
'state' => $row[7],
'city' => $row[8],
'address' => $row[9]
]);
}
Replied to A Non-numeric Value Encountered
@van1310 hey I am also getting same error how did you solve this one?
Replied to How To Use Group By In Laravel
@manelgavalda I am getting this error
SQLSTATE[42000]: Syntax error or access violation: 1055 'schoolmanagement.time_tables.id' isn't in GROUP BY (SQL: select * from `time_tables` where `academic_id` in (24) and `class` in (2, 4) group by `day`)"
Replied to How To Use Group By In Laravel
@manelgavalda I have done strict to false but it is not working
Started a new Conversation How To Use Group By In Laravel
hi,
I am to retrieve data based on the day using groupBy. But I am getting an error like this
syntax error or access violation: 1055
what I have tried
public function index(){
$ids = Academic::active()->pluck('id');
if(Auth()->user()->getRoleNames() == '["Parent"]')
{
$id = Auth()->user()->Parents_id;
$parent = ParentName::find($id);
$students = $parent->students;
foreach($students as $stu)
{
$classid[] = $stu->class_id;
}
$timetables = DB::table('time_tables')->whereIn('academic_id', $ids)->whereIn('class', $classid)->groupBy('day')->get();
// $timetables = TimeTable::whereIn('academic_id', $ids)->whereIn('class', $classid)->get();
return response()->json($timetables);
}
Replied to Unable To Import MySQL Database In Server(Shared Hosting)
@sinnbeck thank you very much I will upgrade my MySQL server and check
Replied to Unable To Import MySQL Database In Server(Shared Hosting)
@sinnbeck yes you are right there is a big difference in version
in local I am using 10.4.6 and in the server, I am using 5.5.61-38.13
how to solve this problem?
Replied to Unable To Import MySQL Database In Server(Shared Hosting)
No, last week I have hosted then it was working. Then how to check the version of mysql?
Replied to Unable To Import MySQL Database In Server(Shared Hosting)
Ya I have seen so many discussion but unable to solve
Started a new Conversation Unable To Import MySQL Database In Server(Shared Hosting)
hi In local it is working fine. While importing the MySQL database in the server, it is importing all the tables not importing the primary and foreign key relationships. In between, I am getting an error like this
#1071 - Specified key was too long; max key length is 767 bytes
Replied to How To Import Csv Data In Mysql With Choose Matching Fields
@itxrahulsingh read this documentation https://docs.laravel-excel.com/3.1/imports/ for importing data into mysql
Replied to Can We Use Model Inside A Jquery Function?
@nakov It is working now thank you very very much
Replied to Can We Use Model Inside A Jquery Function?
yes, I just tried it now. It is giving all the text