mardi 1 octobre 2019

How to set old value for SELECT tag in Laravel

create.blade.php

<select  id="category" class="form-control" name="category"  required>
<option selected disabled>- Select -</option>
<option  value="">
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
</select>

Error : Undefined variable: key (View: C:\xampp\htdocs\LaravelCrud_x\resources\views\create.blade.php)



via Chebli Mohamed

Why "Allowed Memory Size Exhausted" error turns out when using bigger size database

I had using eloquent relationship in my query (controller).

  $items = Item::with('section','category')
                       ->where('item.statusid', '=', 1)
                       ->get();

I had tested in my local and development server and success. But when I use the production database to the same code, it turns error:

   "Allowed Memory Size Exhausted"

I had tried changing php memory limit and disable query log, but failed. What else can I do to fix this?



via Chebli Mohamed

how to set height and width to image uploaded using setImageValue in phpword?

I am using this code and it is uploading the image to the docx it functions well, but the problem the size of the image is too small I need to increase the height and width

$templateProcessor->setImageValue('image',[$image_path,['width' => 40, 'height' => 40]]); it is not working is it even possible?

    $templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor(asset('docx/job_application.docx'));
    $templateProcessor->setImageValue('image',$image_path);
    $templateProcessor->saveAs('docx/'.$file_name.'.docx');


via Chebli Mohamed

Datatables - Yajra returning an incorrect string - Laravel 5.8

I am builing a rather simple page listing UK pubs. There are over 200,000 of them.

I have written a straightforward blade template with datatables being called by ajax to a route in a controller DatatablesController. All works well but I want to add edit and view buttons, so here is my controller function:

  public function getPubs(Request $request)
      {
        $model = Pub::query();
        return DataTables::eloquent($model)
                 ->addColumn('action', function($row){
                           $btn = '<a href="javascript:void(0)" class="edit btn btn-primary btn-sm">View</a>';
                            return $btn;
                    })
                ->addColumn('edit', function($row){
                          $editbtn = '<a href="javascript:void(0)" class="edit btn btn-primary btn-sm">edit</a>';
                           return $editbtn;
                   })
                ->make(true);
      }

The problem is the edit column is returning an incorrect string. Here is the end of the ajax result of the first item:

    "action": "<a href=\"javascript:void(0)\" class=\"edit btn btn-primary btn-sm\">View</a>",
    "edit": "&lt;a href=&quot;javascript:void(0)&quot; class=&quot;edit btn btn-primary btn-sm&quot;&gt;edit&lt;/a&gt;"

I cannot see any reason in my method why this is not correctly returned.



via Chebli Mohamed

Laravel edit records dynamic way

Controllers/HomeController.php

    public function edit(Task $task)
    {       
        return view('edit', compact('task'));
    }   

     public function update(Request $request, Task $task)
    {
        $request->validate(['title' => 'required|min:3', 'description' => 'required', ]);
        $task->title = $request->title;
        $task->description = $request->description;
        $task->save();
        $request->session()
            ->flash('message', 'Successfully modified the task!');
        return redirect('viewalltask');
    }

routes/web.php

Route::get('/{task}', 'HomeController@update')->name('update');

views/edit.blade.php

 <form action="" method="POST">
                 <input type="hidden" name="_method" value="PUT">
                  
                  <div class="row">
                     <div class="col-md-3" >
                        <label for="title" >title</label>
                        <input id="title" type="text" class="form-control" name="title" value="" required autofocus>
                     </div>
                     <div class="col-md-3">
                        <label for="description" >description</label>
                        <input id="description" type="text" class="form-control" name="description" value="" required>
                     </div>
                  </div>
                  <br>
                  <div class="row">
                     <div class="col-md-12">
                        <button type="submit" class="btn btn-primary" >
                        Edit
                        </button>
                     </div>
                  </div>
               </form>

Error :
Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException No message



via Chebli Mohamed

Laravel WithCount using where

i have two tables : Table 1 courses : - id_cours - field_cours

Table 2 Question : - id_quest - field_quest - id_cours - id_user

The question is i want to Count all question just added by the user logged .

i try with this one :

 public function answers()
    {
        return $this->hasMany('App\QuestionUsers','idcours', 'id_cours');

    }

but he count all question added by all users . Please need Help



via Chebli Mohamed

lundi 30 septembre 2019

Laravel support collection not works on the timing have any solution?

Laravel support collection does not work with the date and time. how can I solve it?

$timings = collect([]);

for ($i = 1; $i < 24 ; $i++) {
    $timings->push([
        'start_time' => $i.':50:34'
    ]);
}

Above loop is for the generate 24 hours timings for the example.

When we make this then works fine but include unnecessary timings also.

$timings->where('start_time', '<=', '11:59:59')->where('start_time', '>=', '00:00:00');
$timings->where('start_time', '>=', '12:00:00')->where('start_time', '<=', '23:59:59');

Please help me with this.



via Chebli Mohamed