Results: 1578
Notes
  • Newest first
  • Oldest first
  • Newest first(All)
  • Oldest first(All)
Create an array from variables and their values:

$firstname = "Peter";
$lastname = "Griffin";
$age = "41";

$result = compact("firstname", "lastname", "age");

print_r($result);
by გიორგი ბაკაშვილი
4 years ago
0
PHP
PHP official doc
2
$errors->has() and "is-invalid" related issue
$errors->has('accountable_id')
did not work
@if($errors->has('accountable_id'))
    <div class="invalid-feedback">
        <strong>{{ $errors->first('accountable_id') }}</strong>
    </div>
@endif
Until
is-invalid
class was specified
class="form-control {{ $errors->has('accountable_id') ? 'is-invalid' : '' }}"
The complete example
<div class="form-group">
    <label for="exampleSelect2">Accountable <span class="text-danger">*</span></label>
    <select class="form-control {{ $errors->has('accountable_id') ? 'is-invalid' : '' }}" id="accountable_id" name="accountable_id">
        <option value="">Select Accountable</option>
        @foreach($users as $accountable)
            <option value="{{ $accountable->id }}" {{ $accountable_id == $accountable->id ? 'selected' : '' }}>{{ $accountable->name }}</option>
        @endforeach
    </select>
    @if($errors->has('accountable_id'))
        <div class="invalid-feedback">
            <strong>{{ $errors->first('accountable_id') }}</strong>
        </div>
    @endif
</div>
by Valeri Tandilashvili
4 years ago
0
Laravel
validation
2
Debug errors in Laravel
blade
file on each row
@if ($errors->any())
     @foreach ($errors->all() as $error)
         <div>{{$error}}</div>
     @endforeach
 @endif
by Valeri Tandilashvili
4 years ago
0
Laravel
Validation
2
Laravel latest() and oldest() Eloquent
The latest and oldest methods allow you to easily order results by table column. By default, result will be ordered by the
created_at 
column. You will pass the column name that you wish to sort by using
orderBy 
method. new method latest() eloquent
public function getLatestRecord()
{
    $latests = User::latest()->get();
}
old method OrderBy with latest eloquent
public function getLatestRecord()
{
    $latests = \DB::table('users')->orderBy('created_at','desc')->get();
}
new method oldest() eloquent
public function getOldestRecord()
{
    $oldest = User::oldest()->get();
}
by გიორგი ბაკაშვილი
4 years ago
0
Laravel
2
Soft Deleting
In addition to actually removing records from your database, Eloquent can also "soft delete" models. When models are soft deleted, they are not actually removed from your database. Instead, a
deleted_at
attribute is set on the model indicating the date and time at which the model was "deleted". To enable soft deletes for a model, add the
 Illuminate\Database\Eloquent\SoftDeletes
trait to the model:
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Flight extends Model
{
    use SoftDeletes;
}
You should also add the
deleted_at 
column to your database table. The Laravel
schema builder
contains a helper method to create this column:
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Facades\Schema;

Schema::table('flights', function (Blueprint $table) {
    $table->softDeletes();
});

Schema::table('flights', function (Blueprint $table) {
    $table->dropSoftDeletes();
});
Now, when you call the
delete
method on the model, the
deleted_at 
column will be set to the current date and time. However, the model's database record will be left in the table. When querying a model that uses soft deletes, the soft deleted models will automatically be excluded from all query results. To determine if a given model instance has been soft deleted, you may use the
trashed
method:
if ($flight->trashed()) {
    //
}
Restoring Soft Deleted Models Sometimes you may wish to "un-delete" a soft deleted model. To restore a soft deleted model, you may call the
restore
method on a model instance. The restore method will set the model's
deleted_at 
column to
null
:
$flight->restore();
You may also use the
restore
method in a query to restore multiple models. Again, like other "mass" operations, this will not dispatch any model events for the models that are restored:
Flight::withTrashed()
        ->where('airline_id', 1)
        ->restore();
The
restore
method may also be used when building relationship queries:
$flight->history()->restore();
Permanently Deleting Models
Sometimes you may need to truly remove a model from your database. You may use the
forceDelete
method to permanently remove a soft deleted model from the database table:
$flight->forceDelete();
You may also use the forceDelete method when building Eloquent relationship queries:
$flight->history()->forceDelete();
Querying Soft Deleted Models As noted above, soft deleted models will automatically be excluded from query results. However, you may force soft deleted models to be included in a query's results by calling the withTrashed method on the query:
use App\Models\Flight;

$flights = Flight::withTrashed()
                ->where('account_id', 1)
                ->get();
The withTrashed method may also be called when building a relationship query:
$flight->history()->withTrashed()->get();
Retrieving Only Soft Deleted Models The
onlyTrashed
method will retrieve only soft deleted models:
$flights = Flight::onlyTrashed()
                ->where('airline_id', 1)
                ->get();
by გიორგი ბაკაშვილი
4 years ago
0
Laravel
0
call JS function ("this" context)
Here
this
means the object being clicked
<a class="view_all" onclick="consoleLogMe(this);" href="javascript:">object being clicked</a>
this
means the global object
window
in this example:
<a class="view_all" href="javascript:alertMe(this)">window object</a> 
by Valeri Tandilashvili
4 years ago
1
JavaScript
DOM
0
If we want to commit only part of changes of the same file
--patch
or
-p
is used
git add --patch
Similar to the above command
git add -p
Possible answers for the command:
y
stage this hunk for the next commit
n
do not stage this hunk for the next commit
q
quit; do not stage this hunk or any of the remaining hunks
a
stage this hunk and all later hunks in the file
d
do not stage this hunk or any of the later hunks in the file ... The complete list of the possible answers is on the link of the note
by Valeri Tandilashvili
4 years ago
0
Git
4
Change Timezone in Laravel
set app time zone by configuring
app.php
file in
config
folder . To change
time zone
, modify the value of timezone in
 app.php
file. Here is the appropriate syntax :
 'timezone' => 'Asia/Tbilisi',
by გიორგი ბაკაშვილი
4 years ago
1
Laravel
time zone
5
define a route to this controller method
laravel 8
You can define a route to this controller method like so:
use App\Http\Controllers\UserController;

Route::get('/users', [UserController::class, 'index']);
Route::get('/user/{id}', [UserController::class, 'show']);
Resource Controllers
resourceful route to the controller:

use App\Http\Controllers\PhotoController;
Route::resource('photos', PhotoController::class);
------------------------------------------------------------------------------------
laravel  7, 6, 5
You can define a route to this controller method like so:
Route::get('users', 'UserController@index');
   Route::get('user/{id}', 'UserController@show');
Resource Controllers
resourceful route to the controller:
Route::resource('photos', 'PhotoController');
========================================= This single route declaration creates multiple routes to handle a variety of actions on the resource. The generated controller will already have methods stubbed for each of these actions. Remember, you can always get a quick overview of your application's by running the
route:list
Artisan command.
Actions Handled By Resource Controller

Verb	URI	Action	Route Name
GET	/photos	index	photos.index
GET	/photos/create	create	photos.create
POST	/photos	store	photos.store
GET	/photos/{photo}	show	photos.show
GET	/photos/{photo}/edit	edit	photos.edit
PUT/PATCH	/photos/{photo}	update	photos.update
DELETE	/photos/{photo}	destroy	photos.destroy
by გიორგი ბაკაშვილი
4 years ago
0
Laravel
Controllers
3
Create and Manage Databases in MySQL and MariaDB
To begin, sign into MySQL or MariaDB with the following command:
mysql -u root -p
create a database by typing the following command:
CREATE DATABASE new_database;
To view a list of the current databases that you have created, use the following command:
SHOW DATABASES;
by გიორგი ბაკაშვილი
4 years ago
0
Linux
MySQL
2
Results: 1578