mardi 31 mai 2022

Laravel Eloquent Query Building ORM

Let's assume, There Is two Table 'student' & 'state', 'student' table contain 'id', 'name', 'state_id'. and 'state' table contain 'id', 'state_name'. In 'student' table contain the corresponding State ID.

Now I want to fetch the student's details including the state name. (Note: In the student table, I contain only the state id) How can I achieve this?



via Chebli Mohamed

lundi 30 mai 2022

DateTime::__construct(): Failed to parse time string (May 5 2022 12:00:00:AM) at position 20 (:): Unexpected character

I'm having the following error

"

ErrorException in /*/web/vendor/nesbot/carbon/src/Carbon/Carbon.php line 555:
DateTime::__construct(): Failed to parse time string (May 5 2022 12:00:00:AM) at position 20 (:): Unexpected character

In my list file,

         

    

The date in sql is a date time "2020-05-20 08:13:00.000"

I've tried some changes like format from DateTime to format to day, I've tried also to parse string and nothing worked.. I've seen some post with the same error but nothing result. Please help me



via Chebli Mohamed

Data repeat for eloquent query in Laravel 8

$data = EmpData::leftJoin('states', 'states.id', 'emp_data.empState')
        ->leftJoin('districts', 'districts.id', 'emp_data.empDistrict')
        ->selectRaw('emp_data.*, states.name as stateName')
        ->selectRaw('emp_data.*, districts.name as districtName')
        ->paginate(30); 

In my model 'EmpData' I contain state id and district id, and the 'state' & 'district' table includes the name of the state or district. so I use left join. Data fetch correctly, but it returns 4 times data, how can I fix it.



via Chebli Mohamed

dimanche 29 mai 2022

How can I upload pictures with queue in laravel

When uploading many images, and the size is large, it takes a lot of time, and sometimes the site appears to be unavailable due to the large size. Can this problem be solved?



via Chebli Mohamed

How to do login using angular and laravel api?

login.component.html

<form class="form-horizontal" #loginForm="ngForm" (ngSubmit)="onSubmit(loginForm)">
    <fieldset>
        <div class="control-group">
            <label class="control-label" for="email">E-mail</label>
            <div class="controls">
                <input type="text" id="email" name="email" placeholder="" class="input-xlarge" ngModel>
            </div>
        </div>

        <div class="control-group">
            <label class="control-label" for="password">Password</label>
            <div class="controls">
                <input type="password" id="password" name="password" placeholder="" class="input-xlarge" ngModel>
            </div>
        </div>

        <div class="control-group">
            <div class="controls">
                <button class="btn btn-success">Login</button>
            </div>
        </div>
    </fieldset>
</form>

login.component.ts

import { HttpClient } from '@angular/common/http';
import { Component, OnInit } from '@angular/core';
import { NgForm } from '@angular/forms';

@Component({
    selector: 'app-login',
    templateUrl: './login.component.html',
    styleUrls: ['./login.component.css']
})
export class LoginComponent implements OnInit {

    constructor(private http:HttpClient) { }

    ngOnInit(): void {
    }

    onSubmit(form:NgForm){
        const email = form.value.email;
        const password = form.value.password;
        this.http.post("http://127.0.0.1:8000/api/signin",{
            email: email,
            password:password
        }).subscribe((res)=>{
            console.log(res);
        },
        err=>{
            console.log(err);
        });
    }
}

api.php

Route::post('/signin', 'AdminController@signin')->name("signin");

AdminController.php

<?php
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use App\User;
use DB;

class AdminController extends Controller
{
    public function signin(Request $request)
    {
        $credentials = $request->only('email', 'password');
        if (Auth::attempt($credentials)) 
        {
            return response(['message'=>'login success!!'], 200);
        }
        else
        {
            return response(['message'=>'Login details are invalid'], 200);
        }
    }
}

I am new in angular and In above code I am simply want to login using angular and laravel web API. What happen here I am successfully pass parameter using angular and also successfully got in AdminContoller function i.e. signin function when I try to print to check the value of email and password then it show successfully but when I try to login via email and password then it always show Login details are invalid message. I don't know where am I doing wrong? Please help me.

Thank You



via Chebli Mohamed

vendredi 27 mai 2022

how can I make each

i have the following code in php using laravel blade which allows me to get all the days of the current month as a table , I want to make each "" clickable with php , im not sure if thats possible.

    <table class="table-bordered">
  <tbody>
@php
$date = date('F Y');//Current Month Year
$row_count=0;
$col_count=0;

while (strtotime($date) <= strtotime(date('Y-m') . '-' . date('t', strtotime($date)))) {
if($row_count%4==0){
        echo "<tr>";
        $col_count=1;
     }
    $day_num = date('j', strtotime($date));
    $month_num = date('m', strtotime($date));
    $day_name = date('l', strtotime($date));
    $day_abrev = date('S', strtotime($date));
    $day = "$day_name $day_num";
    $date = date("Y-m-d", strtotime("+1 day", strtotime($date)));
    echo '<td>' . $day . '</td>';
    if($col_count==4){
           echo "</tr>";
        }
        $row_count++; 
        $col_count++; 
}
@endphp
  </tbody>
</table>


via Chebli Mohamed

mercredi 25 mai 2022

php artisan optimize handling the post-update-cmd event returned with error code 255

I run composer update to laravel 5.2 project. The website returns HTTP:500 error and php artisan commands returns blank. Please help me with your experience



via Chebli Mohamed