Skip to content

Instantly share code, notes, and snippets.

Laravel

routes:
In laravel routes are seen in routes/web.php file

Route::get('/', function () {
    return view('welcome');
});

requests:

According to the official website MongoDB is a document database that provides high performance, high availability, and easy scalability.
MongoDB falls into the group of documents-oriented NoSQL databases
steps to use mangodb with php:

  1. Head on over to the downloads page on the MongoDB official website. Click on the download link for the latest stable release under Windows. Install it
  2. Windows users can download precompiled binaries of the extension from PECL. After extracting the php_mongodb.dll file to PHP’s extension directory, add the following line to your php.ini file: extension=php_mongo.dll
  3. Following is the preferred way of installing this library with Composer
    composer require mongodb/mongodb

Array_filter() :

<?php
class Post
{
    public $title;
    public $published;

    public function __construct($title, $published){
 $this-&gt;title = $title;
  • Database
    • Connection.php
    • QueryBuilder.php
  • index.php
  • task.blade.php
Connection.php
<?php
class Connection
<?php 

try {
    $pdo = new PDO('mysql:host=localhost;dbname=test', 'root', '');
}catch( PDOException $e ){
    die("couldn't connect ".$e->getMessage());//gives error message
}

$statement = $pdo->prepare('select * from todos');
<?php
$host = 'localhost';
$user = 'root';
$password = '123456';
$dbname = 'pdoposts';
// Set DSN
$dsn = 'mysql:host='. $host .';dbname='. $dbname;
// Create a PDO instance

php

Associative Arrays:
index.php

<?php 
$person = [
	'age' => 31,
	'hair' => 'brown,
	'career' => 'web developer'
];

one to one :
user can have profile or address user has one profile:
add this in user model as:

public function profile()
{
 return $this->hasOne(Profile::class);
}

check the following links for the useful packages in Laravel:
https://www.cloudways.com/blog/best-laravel-packages/

  • barryvdh/laravel-debugbar : Link
    This is a package to integrate PHP Debug Bar with Laravel
  • Socialite : Link
    Socialite is a very popular package for handling social authentication with OAuth. It works with Facebook, Twitter, Github, Bitbucket, and a few others.
  • LARAVEL-MODULES : Link
    Laravel package which was created to manage your large Laravel app using modules.
  • arrilot/laravel-widgets : Link
    Generate and use widgets

My Laravel Documentation

  • Create Thread model, migration and Resourceful controller

    php artisan make:model Thread -mr

  • Create Reply model, migration and simple controller

    php artisan make:model Reply -mc