mercredi 11 janvier 2023

Get data eloquent to Dompdf with response->json in laravel

How to get data eloquent to Dompdf with response->json in laravel. if i use,

$pdf = PDF::loadview('ipdf',['ipdf'=>$ipdf]);
return $pdf->stream();

if i dont use it, img

My controller

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use PDF;
use App\Http\Controllers\Controller;
use App\Helpers\MessageHelper;
use App\Helpers\StockHelper;
use Illuminate\Http\JsonResponse;
use App\Helpers\StringRandomHelper;
use App\Models\Order;
use App\Models\OrderDetail;
use App\Models\Sablon;
use App\Models\Stock;
use App\Models\Customer;
use App\Models\ProductSize;
use DB;
class IpdfController extends Controller
{
    public function __construct()
    {
        $this->model = new Order;
    }

    public function index(Request $request) {
        $ipdf = Order::with('orderDetail')->paginate(15);
        return view('ipdf', ['ipdf'=>$ipdf]);
    }
    public function cetak_pdf($id)
    {
        $ipdf = $this->model->with(['orderDetail.productSize.productColor.productCategories.product'])->find($id);
        $ipdf = $ipdf->where('id', '=', $id)->orderby('created_at','desc')->get();
        return response()->json($ipdf);
        // $pdf = PDF::loadview('ipdf',['ipdf'=>$ipdf]);
        // $pdf = PDF::loadview('ipdf',compact('ipdf'));
        // return $pdf->stream();
    }
}

get/read data eloquent by id to Dompdf with response->json in laravel



via Chebli Mohamed

samedi 7 janvier 2023

problems with login and authentication in laravel

i need help with my login and authentication of admin. In the database I have a table called 'admins' with coulums of 'name', 'surname', 'password' in my native language

Every time i press the login button when i try to log in i get an error:

"Undefined index: password"

where password is in English in folder:

C:\wamp\www\app\vendor\laravel\framework\src\Illuminate\Auth\EloquentUserProvider.php

and i dont know why.

My custom controller AuthController:

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Hash;
use Session;
use App\Models\Admin;
use Illuminate\Support\Facades\Auth;
class AuthController extends Controller
{
    public function index()
    {
        return view('auth.login');
    }  
      
    public function customLogin(Request $request)
    {
        $request->validate([
            'name' => 'required',
            'surname' => 'required',
            'passw' => 'required',
        ]);
   
        $credentials = $request->only('name', 'surname', 'passw');
        if (Auth::attempt($credentials)) {
            return redirect()->intended('');
        }
  
        return redirect("login")->withSuccess('Wrong input data.');
    }
    
    public function dashboard()
    {
        if(Auth::check()){
            return view('');
        }
  
        return redirect("login")->withSuccess('Wrong input data.');
    }
    
    public function signOut() {
        Session::flush();
        Auth::logout();
  
        return Redirect('');
    }
}

My route:

Auth::routes();
Route::post('/login', 'AuthController@customLogin');

I consulted with a acquaintance that specialises in web-programming and she said i should do a custom AuthController, which I did, but the problem is either still not fixed or this is a different error. And from websources i used: https://www.positronx.io/laravel-custom-authentication-login-and-registration-tutorial/



via Chebli Mohamed

vendredi 6 janvier 2023

How to compare a db value to another db value in laravel php

I would like to compare 2 values of the database. Is it possible to do so with the "where" method? The "tnx_time" would be one db value and the "value(duration)" the other one. But right now I can not access the db values on the 3rd field of the "where" function.

Does anybody know how to fix that? Thanks a lot!

$trnxs =  Transaction::where('tnx_time', '<',  date("Y-m-d", strtotime( value(duration) )) )


via Chebli Mohamed

mercredi 4 janvier 2023

how to check a mutex exists for a scheduled job using laravel tinker?

I have a job scheduled to run every hour. 'withoutOverlapping' is set for this job and mutex expiry time is 24 hour.

But when I checked cron.log. I found that it is not running every hour. But it runs once in a day and at the end of job, there is a redis write error. I think this error is getting when clearing mutex (lock) of this job from redis after completion of job execution. Then after 24 hour, mutex expires automatically, then this job runs next hour.

To check mutex clears from redis or not, I need to see mutex of this job exists. So I tried below cod in tinker but it is showing zero events. Actually there are 7 jobs scheduked

>>> $s = new Illuminate\Console\Scheduling\Schedule();
=> Illuminate\Console\Scheduling\Schedule {#3543}
>>> count($s->events())
=> 0
>>>

So using tinker how can I achieve this ?



via Chebli Mohamed

mardi 3 janvier 2023

How to use X-component in laravel controller side

index.blade.php

<x-textbox divClass="col-sm-4" name="datbase_ffieldname" :model="$model" readonly>                                 
    </x-textbox>
  • This file is working done but same code not working in controller side

studentController.php

$textbox = <x-textbox divClass="col-sm-4" name="datbase_ffieldname" :model="$model" readonly>                                 
    </x-textbox>;

print_r($textbox);

not get the textbox data



via Chebli Mohamed

lundi 2 janvier 2023

exception": "Illuminate\\Database\\QueryException "SQLSTATE[23000]: Integrity constraint violation:1052 Column 'id' in field list is ambiguous

This method i try

$questions = DB::table('questionbank')
    ->join('questionbank_quizzes', 'questionbank_id.id', '=', 'questionbank.id')
    ->join('quizzes', 'quizzes.id', '=', 'questionbank_quizzes.quize_id')
    ->where('subject_id', '=', $request->subject_id)
    ->get(['id', 'subject_id', 'topic_id', 'question_type', 'question', 'marks', 'difficulty_level', 'status', 'quizzes.title']);

and the error is

SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'id' in field list is ambiguous (SQL: select id, subject_id, topic_id, question_type, question, marks, difficulty_level, status, quizzes.title from questionbank inner join questionbank_quizzes on questionbank_id.id = questionbank.id inner join quizzes on quizzes.id = questionbank_quizzes.quize_id where subject_id = 78)

I want to return in this format can any suggest what we have to do? {id: 2665, subject_id: "78", topic_id: "95", question_type: "radio",…}

But in scipt has other method but we have to print same data as above

$subject_id = $request->subject_id;
$subject = Subject::where('id','=',$subject_id)->first();
$topics = $subject
    ->topics()
    ->where('parent_id', '=', '0')
    ->get(['topic_name', 'id']);
$questionbank_id = DB::table('questionbank')
    ->where('subject_id', '=', $request->subject_id)
    ->get(['id']);
// $questionbank_quizzes = $questionbank_id->DB::table('questionbank_quizzes')
//     ->where('questionbank_id', '=', $questionbank_id[]->id)
//     ->get(['quize_id', 'questionbank_id']);
// $quiz_n=quizzesExistTitle()->get(['title']);
$questions = $subject->questions()->get(['id', 'subject_id', 'topic_id', 'question_type', 'question', 'marks', 'difficulty_level', 'status']);
// $questions = DB::table('questionbank')
//    ->join('questionbank_quizzes', 'questionbank_id.id', '=', 'questionbank.id')
//    ->join('quizzes', 'quizzes.id', '=', 'questionbank_quizzes.quize_id')
//    ->where('subject_id', '=', $request->subject_id)
//    ->get(['id', 'subject_id', 'topic_id', 'question_type', 'question', 'marks', 'difficulty_level', 'status']);

return json_encode(array('topics' => $topics, 'questions' => $questions, 'subject' => $subject, 'questionbank_quizzes' => $questionbank_id));

I have to show in array quizzes.title. I have try:

$questions = DB::table('questionbank')
    ->join('questionbank_quizzes', 'questionbank_id.id', '=', 'questionbank.id')
    ->join('quizzes', 'quizzes.id', '=', 'questionbank_quizzes.quize_id')
    ->where('subject_id', '=', $request->subject_id)
    ->get(['id', 'subject_id', 'topic_id', 'question_type', 'question', 'marks', 'difficulty_level', 'status', 'quizzes.title']);

but got above error



via Chebli Mohamed

405 method not accepted laravel on live server

I'm creating Api's in laravel 5.7 with php version 7.4 using passport Its an Api of Signin. The Api works fine on local server but when we try it on live server it gives an error of 405 method not accepted. Don't know why its like that because its working fine on local server but not on live server



via Chebli Mohamed