Friday, 13 July 2018

array_push() merging multiple array

That's because you're adding a non-object to the last element of the array.
Here i suppose you get an array of objects with the name property
$competition_all = Competition::all();
Here you add a key=>value pair to the last element of the objects array
$newCompete = array('name'=>'Others');
array_push($competition_all, $newCompete);
Here you walk through the array of objects and when it comes to the last element the "$competition_games->name" has no name property
foreach ($competition_all as $competition_games) {
            $this->competition_games[$competition_games->name] = $competition_games->name;
        }
Try something like including a stdclass for it like :
$newCompete = new StdClass();
$newCompete->name = 'Others';
array_push($competition_all, $newCompete);

Merging into New Laravel Collection



resources :

https://stackoverflow.com/questions/23599584/how-to-manually-create-a-new-empty-eloquent-collection-in-laravel-4

Wednesday, 11 July 2018

Interview Training

connect mysql from cli :

cd  "C:\wamp64\bin\mysql\mysql5.7.21\bin"

C:\wamp64\bin\mysql\mysql5.7.21\bin > mysql.exe -u root


Microsoft .Net  utilities :

1. Entity Framework
2. LinQ .(Net Integrated Query)

Wednesday, 4 July 2018

Thursday, 14 June 2018

Check if empty in collection


When using ->get() you cannot simply use any of the below:
if (empty($result)) { }
if (!$result) { }
if ($result) { }
Because if you dd($result); you'll notice an instance of Illuminate\Support\Collection is always returned, even when there are no results. Essentially what you're checking is $a = new stdClass; if ($a) { ... } which will always return true.
To determine if there are any results you can do any of the following:
if ($result->first()) { } 
if (!$result->isEmpty()) { }
if ($result->count()) { }
if (count($result)) { }

Monday, 7 May 2018

Date Format to Template and Validation

At Validation

  'dob' => 'required|date_format:"d/m/Y"|before:"2006-01-01"',


At View Template

  {{$submissions->created_at->format("F d, Y")}}


Reference

1. https://stackoverflow.com/questions/32080734/laravel-validation-date-does-not-match-the-format?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa

2. http://php.net/manual/en/function.date.php

3. https://stackoverflow.com/questions/24441395/how-to-change-default-format-at-created-at-and-updated-at-value-laravel?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa

Saturday, 5 May 2018

Return Old Input After Validation

From Controller (UserController)

  $validator = Validator::make($request->all(), [
          'first_name' => 'required|max:100',
          'last_name' => 'required|max:100',
          'gender' => 'required|numeric',
          'dob' => 'required|date|before:"2006-01-01"',
          'email' => 'required|email',
          'mobile' => 'required|numeric',
          'street' => 'required|max:255',
          'city' => 'required|alpha|max:20',
          'state' => 'required|numeric',
          'post_code' => 'required|numeric',
      ], $messages);


      if ($validator->fails()) {
          return redirect()->back()
                      ->withErrors($validator)
                      ->withInput($request->input());
      }