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

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());
      }



Thursday, 3 May 2018

Laravel Custom Login Validation

   public function __construct()
   {
      $this->middleware('guest')->except('logout');
   }

  /**
  * Get the failed login response instance.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\RedirectResponse
  */
  protected function sendFailedLoginResponse(Request $request)
  {
      $errors = [$this->username() => trans('auth.failed')];
      // Load user from database
      $user = \App\User::where($this->username(), $request->{$this->username()})->first();
      if($user==null){
        $errors = ['email' => 'Invalid Email. Please try again'];
      }else{
        // Check if user was successfully loaded, that the password matches
        // and active is not 1. If so, override the default error message.
        if (!Hash::check($request->password, $user->password)) {
            $errors = ['password' => 'Invalid Password. Please Try again'];
        }

      }

      if ($request->expectsJson()) {
          return response()->json($errors, 422);
      }
      return redirect()->back()
          ->withInput($request->only($this->username(), 'remember'))
          ->withErrors($errors);
  }

Reference :

https://gist.github.com/SaeedPrez/b3d35af0bb039e8b8d5caf85ec3b2476
https://laravel-news.com/login-validation

Monday, 30 April 2018

Redirected after Login or Register

in Login Controller, it was located under Illuminate\Foundation\Auth\AuthenticatesUsers;

then change this function to :

  /**
     * The user has been authenticated.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  mixed  $user
     * @return mixed
     */
    protected function authenticated(Request $request, $user)
    {
      return redirect('/admin');
    }


while for Register Controller, it was located under Illuminate\Foundation\Auth\RegistersUsers;

then change this function to : 

    /**
     * The user has been registered.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  mixed  $user
     * @return mixed
     */
    protected function registered(Request $request, $user)
    {
        return redirect('/admin');
    }

however RegisterController has a constant variable   protected $redirectTo = '/home'; which you can just change their value to your target url.

reference 

https://stackoverflow.com/questions/44173616/laravel-5-4-how-do-i-find-logincontrollershowloginform

https://stackoverflow.com/questions/42177044/laravel-5-4-redirection-to-custom-url-after-login

Saturday, 28 April 2018

Friday, 27 April 2018

Merging Input Request

Often you want to pass value for input type hidden, this can be submitted by merging with another form request to the controller





Reference

https://stackoverflow.com/questions/23073633/laravel-change-input-value/36549464#36549464

Wednesday, 25 April 2018

Layer 1 - Physical Layer

Ethernet and Ethernet based cables to make L1 connection happer.

Ethernet

- speeds , cap
- including unshielding twisted-pair (utp) , shielding twisted copper (stp)
- twisting cables minimize the effect of EMI from outside sources
- twisting cables lessens the amount of EMI from going out from cable itself.
- stp easily damaged and cost more
- fibre optic is cost more from copper cable
- have a maximum cable of 100 meters
- switching between ethernet speeds and capabilities would be not problem because
ethernet has standards as below.

copper based standards :
- regularly runs at 10 Mbps
- IEEE name :  10BASE-T
- fast ethernet, clocking at 100Mbps, IEEE name standard is 802.3u (100Base-T)
- normal Ethernet and fast Ethernet use only two pair  of wires out of the four available
- Gigabit Ethernet, bringing 1000Mbps, IEEE name stnadard 802.3ab (1000Base-T)
- while gigabit ethernet use all four pair of wires in the cable
- 10 Gig Ethernet runs at 10Gbps, IEEE name standard is 802.3an (10GBase-T)

the fibre optic standard :
- fiber standards jump right to Gigabit Ethernet, running at 1000Mbps
- network admins call it 1000Base-LX, while IEEE standard is 802.3z

Cable Types 

Crossover and straight through cabling
- for the host to switch connections, we'll need straight through cables, so named because the wires in the cable run straight from a particular pin at the host end to the same numbered pin at the switch end.


-whilst switch to swith connection using crossover cable since transmit ports and receive port needed to be different at one end pin.


- Auto MDI-X  (Automatic Medium-Dependent Interface Crossover), eventually cisco switch got automatic discover cable if newly straight-through cable were set up between two switch. You need to set cisco switch port, set speed, duplex and mdix to auto that port.

**auto mdi-x formula*
same device = crossovercable
not same type of devices = straight-through cable

SW1(config)#int fast 0/1
SW1(config-if)#speed auto
SW1(config-if) #duplex auto
SW1(config-if)#mdix ?
auto Enable automatic MDI crossover detection on this interface
SW1(config-if)#mdix auto

Ethernet Header

Preamble | Start Frame Delimiter (SFD) | Dest. MAC Address | Source MAC Address | Protocol Type

Definitions
1. Preamble : A seven-byte set of alternating ones and zeroes 10101010, repeated seven times. Used for clock synchronization.

2. SFD : One-byte field set to 10101011, used to indicate preamble's end and that the destination MAC address will immediately follow.

3. Destination MAC Address : The frame's destination.

4. Source MAC address : The frame's  source

5. Protocol Type : Can be IPV4 protocol and occasionally IPV6.

Ethernet Trailer

1. Frame Check Sequence (FCS)
- strictly for error detection, 
2. Cyclic Redundancy Check ( a complex mathematical operation )
- sender arrives at a value by running a cyclic redundancy check against the data contained in the frame, resulting in a numeric value. that value is placed into FCS and the frame is then transmitted.
- the recepient of the frame will run the same CRC against frame's data and compares the answer to that contained in incoming CRC. if the compared values are the same, the frame is non-corrupt and life goes on. otherwise the frame is corrupted and will be discarded.


Hubs

Also known as single collision domain.
Now to prevent the loss of data and time associated with collisions, Carrier Sense Multiple Access
with collision detection (CSMA/CD) was developed. Here's the CSMA/CD process:

1. before sending data, a host will check to see if any other host is already sending data.

2. if that check reveals another host is sending data, the host backs off for a few miliseconds before it listens to the same wire again. If no one's sending data, the host sends the data signal.

3. if 2 PCs happen to send data at the exact time after listening to the wire, the voltage on the wire itself changes, signaling to the hosts that a data collision has occured.

4. The PCs that sent the data will generate a jam signal, indicating to other hosts that data should not be transmitted at this time.

Disadvatages of hub :

1. high level of delay sensitivity when handling voice and video traffic. (one big collision domain)

2. every single time a host connected to this hub sends a broadcast, every other host on that hub will receive a copy of that broadcast. there is no other way to limit the scope of the broadcast and preventing the unnecessary spreading (propagation) of a broadcast through network.

Quick Review

1. hubs give us one collision domain consisting of all connected hosts, one broadcast domain containing those same hosts, and allow only one host to transmit a time.

2. bridges allow us to logically segment the network and to lessen the size of collision domains, but do nothing to segment broadcast domains.

3. switches bring us one-host collision domains and the capability to logically segment the broadcast domain, although that's not done by defa  ult.


Monday, 23 April 2018

CSS - Simple Hover Effects Button

You can add some animation that capture user attention when they hovering buttons (may applied on cards)

Reference :

https://codepen.io/giana/pen/BZaGyP?editors=1100


Inherit "keyword" css reference


<!DOCTYPE html>
<html>
<head>
<style>
span {
    color: blue;
    border: 1px solid black;
}
.extra span {
    color: inherit;
}
</style>
</head>
<body>

<div>
Here is <span>a span element</span> which is blue, as span elements are set to be.
</div>

<div class="extra" style="color:green">
Here is <span>a span element</span> which is green, because it inherits from its parent.
</div>

<div style="color:red">
Here is <span>a span element</span> which is blue, as span elements are set to be.
</div>

</body>
</html>

Wednesday, 4 April 2018

Remove /Public folder (Laravel)

Step 1. Create .htaccess file in root directory

Step 2. Edit .htaccess file to following code

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    RewriteCond %{REQUEST_FILENAME} -d [OR]
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^ ^$1 [N]

    RewriteCond %{REQUEST_URI} (\.\w+$) [NC]
    RewriteRule ^(.*)$ public/$1

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ server.php

</IfModule>

Tuesday, 3 April 2018

LAN SWITCHING

This knowledge will be covered on CISCO CCIE topics.

Topic that will covered :

1. Ethernet Basics
2. Virtual LANs and VLAN Trunking
3. Spanning Tree Protocol

FAST ETHERNET
Fast Ethernet standard is a networking that supports data transfer rates up to 100 Mbps. 100Base-T is based on the older Ethernet standard . Because it is 10 times faster than Ethernet, it is often referred to as Fast Ethernet. Officially, the 100Base-T standard is IEEE 802.3u.

Like Ethernet, 100BASE-T is based on the CSMA/CDLAN access method. There are several different cabling schemes that can be used with 100BASE-T, including :

100BASE-TX : two pairs of high-quality twisted-pair wires
100BASE-T4 : four pairs of normal-quality twisted-pair wires
100BASE-FX : fiber optic cables

Normal vlan gateway last resort is 10.10.0.1 to network 0.0.0.0

Monday, 29 January 2018

Getting SSH Key for Gitlab & Source Tree

Step 1 : Generate id_rsa public key by typing  : ssh-keygen -t rsa -b 4096 -c "youremail@com" on your command prompt.

Step 2 : Now open public key file and copy paste to gitlab at the ssh key section.

Step 3 : After that go to source tree and navigate to Tools > Add SSH key

Step 4 : Then check the connections  via "ssh -v git@gitlab.com"

Step 5 : If success,  you can now clone , pull, push or check out within your branches.

Step 6 : Otherwise, try git CLI to get it done manually if (Source Tree) problem occurs.

Source Reference :

https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/

Working with Private Repo (GitLab)

To clone :

git clone https://YOUR_USER_NAME:PASSWORD@gitlab.com/root/filename.git

Tuesday, 23 January 2018

Redirect if not authenthicated laravel 5.4

the path is defined in app/Exceptions/Handler.php
/**
     * Convert an authentication exception into an unauthenticated response.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Illuminate\Auth\AuthenticationException  $exception
     * @return \Illuminate\Http\Response
     */
    protected function unauthenticated($request, AuthenticationException $exception)
    {
        if ($request->expectsJson()) {
            return response()->json(['error' => 'Unauthenticated.'], 401);
        }

        return redirect()->guest('elsewhere');
    }

Monday, 22 January 2018

Laravel 5.4 and higher version ( Specified key was too long when doing migration)

Specify a smaller length for your e-mail:
$table->string('email', 250);
Which is the default, actually:
$table->string('email');
And you should be good.
For Laravel 5.4 you can find a solution in this Laravel 5.4: Specified key was too long error, Laravel News post:
As outlined in the Migrations guide to fix this all you have to do is edit your AppServiceProvider.php file and inside the boot method set a default string length:
use Illuminate\Support\Facades\Schema;

public function boot()
{
    Schema::defaultStringLength(191);
}

Soure :

https://stackoverflow.com/questions/23786359/laravel-migration-unique-key-is-too-long-even-if-specified

Upgrading to Laravel 5.5 with current project

Step 1 : Change php version that currently your localhost server using (Wamp = php 7.0)

enter image description here

Step 2 : Uninstall and install composer again and select the correct php version (7.0) while setup

enter image description here

Step 3 : If error still occur. Try using 'composer install --ignore-platform-reqs' to setup your project folder

Friday, 19 January 2018

npm run dev

Problem : laravel-5-4-cross-env-is-not-recognized-as-an-internal-or-external-command

You need to make cross-env working global instead of having in in the project.
1) remove node_modules folder
2) run
npm install --global cross-env
3) remove "cross-env": "^5.0.1", from package.json file devDependencies section. Actually, you can skip this step and keep package.json intact. If you prefer.
4) run
npm install --no-bin-links
5) run
npm run dev
and see it working