lundi 30 avril 2018

Migration doesn't update database

I have this simple code which when I run - it does not do anything at all. When I migrate, the migration runs - I have feedback from console: Migrated..... But the database stays the same. In migrations table I see my migration, also with a correct batch.

<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class AddDateToProgram extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('schedules', function(Blueprint $table) {
            $table->string('day')->default('2018-05-24')->nullable();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('schedules', function(Blueprint $table) {
            $table->dropIfExists('day');
        });
    }
}



via Chebli Mohamed

Which is the best folder to store the images/files in Laravel?

Which is the best folder to store the images/files on server in Laravel ? Public or Storage?



via Chebli Mohamed

samedi 28 avril 2018

Laravel 5.1 Guzzle - Undefined offset: 0

I need to access an API so I use guzzle6 and I write a function:

public function test()
    {

$client = new GuzzleHttp\Client(['defaults' => ['verify' => false]]);

try {
$res = $client->post('https://example.com/api/v2/oauth/token?grant_type=client_credentials', [
    'headers' => [
        'Content-Type' => 'application/x-www-form-urlencoded',
    ],

    'auth' => [
        'Username' => 'user_5639',
        'Password' => 'pass_asdhbas67yausihd7qaw8'
]
            ]);

$res = json_decode($res->getBody()->getContents(), true);
}

catch (GuzzleHttp\Exception\ClientException $e) {
        $response = $e->getResponse();
        $result =  json_decode($response->getBody()->getContents());

    return response()->json(['data' => $result]);
}

    }

but I got error:

ErrorException in Client.php line 346: Undefined offset: 0

When I try at POSTMAN the same request everything is fine: enter image description here

How to solve my problem?



via Chebli Mohamed

vendredi 27 avril 2018

Laravel 5.1/5.6 How to send a url in email blade

I am using Mail::send function to send emails to my end users with dynamically generated links in them Below is my sample code for the function - $myemail = "some email adderess"; $myurl = "some url that will be emailed";

Mail::send('emails.mybladetemplate', ['myemail' => $myemail] , function ($message) use ($myemail){

$message->subject('Your favorite links');
$message->from('someone@company.com', 'Company');
$message->to($myemail);
});

I am having trouble passing $myurl to the blade template and publishing it. I even used HTML in my blade template but no success. I have tested Mail::send with other templates and it works fine. Just not when I pass the variables.



via Chebli Mohamed

jeudi 26 avril 2018

what this mean : 'middleware' => 'auth:api'],

When i use in my progame Route::group(['prefix' => 'api/v1', 'middleware' => 'auth:api'], function () { doesn't works . All users can't access for open my project and i added column in table user.



via Chebli Mohamed

mercredi 25 avril 2018

ReflectionException in Route.php line 280: Class App\Http\Controllers\api/v1\SiteController does not exist

I want to immerge two laravel projects so they can have the same authentication,once i login in the first, the second will also login. The first laravel project works with API_Token, so i'm trying to add it in the second project. Since i have the two projects working with laravel 5.2 i followed the next steps: I added a column called api_token to users table - I added a route group where i placed only the dashboard just for test

  Route::group(['prefix' => 'api/v1', 'middleware' => 'auth:api'], function () {
    Route::post('/dashboard', 'SiteController@getDashboard');
});



via Chebli Mohamed

How to change different header for various pages in laravel

I need call different header for hosting and about pages mentioned below, while executing the below code I'm getting error as "Undefined class constant 'hosting'". suggest me how to solve this and call different headers for various pages.

@if(Route::hosting == 'hosting')
{
  @include('partials.header');
}
@elseif(Route::About == 'About'){
   @include('partials.header1');
}
 @endif



via Chebli Mohamed

mardi 24 avril 2018

Update URL from a blade view part

I'm looking on a way to update an url from blade. I want to sort a table, with two icons next to column's name. One to sort on ascending, the other on descending. My goal is to be able to add two parameters to the url, but to keep the original one first.

For exemple, I have this url :

localhost:8000/building

and by clicking on my icon I will get :

localhost:8000/building?sortingObject=name&sortingOrder=asc

but I also can have

localhost:8000/building?search=8

and by clicking on my icon I want to get :

localhost:8000/building?search=8&sortingObject=name&sortingOrder=asc

I tried this :

<a href="">
    <span class="glyphicon glyphicon-sort-by-attributes-alt text-secondary" aria-hidden="true"></span>
</a>

But it's really raw, it cumulates same parameters every time I click on a sort button, and it also needs to know if there is other parameters before (to choose between '&' or '?').

I saw some methods but it always needs to know every parameters to construct a new URL. Is there a way to do this directly in my blade file, or do I need to do this in my controller ?

Thanks by advance



via Chebli Mohamed

lundi 23 avril 2018

Is it possible to print the value of Key from the (key-value)pair of json object in laravel

How to print the 'key' value from the json object in laravel. Find below the json array.

 "pricing": {
"in": {
  "categories": [
    "ccTLD",
    "Geography"
  ],
  "addons": {
    "dns": true,
    "email": true,
    "idprotect": true
  },
  "group": "",
  "register": {
    "1": "704.39"
  },
  "transfer": {
    "1": "704.39"
  },
  "renew": {
    "1": "704.39"
  }
},

Suggest me a solution to display "in" from the above data.



via Chebli Mohamed

samedi 21 avril 2018

laravel 5.1 middleware class not exist

I have implemented my own middleware on local machine. It is working fine on local machine. But, when I uploaded the files on server, then it gives the error like middleware class not exist. Same error given when I created the custom helper.



via Chebli Mohamed

vendredi 20 avril 2018

How to fetch paypal transaction details from url?

I have done a PayPal transaction, payment was successful and redirected to my page. But I need the transaction details should be visible on my page. how to do that? It said use Instant Payment Notification but I didn't get an idea how to use that to fetch details from URL.



via Chebli Mohamed

jeudi 19 avril 2018

Auth for multiple users laravel

public function postSignIn(Request $request)

{

    $this->validate($request, [
        'email' => 'required',
        'password' => 'required'

        ]);


    if (Auth::attempt(['email' => $request['email'], 'password' => $request['password'], 'active' => 1]))
    {
        return redirect()->route('dashboard');
    }
    return redirect()->back()->with('message', 'Email address and Password mismatch or account not yet activated.');
}

if someone know how to make all user use to web site with one auth please tell me how to do it ?



via Chebli Mohamed

mardi 17 avril 2018

How to slove this error in laravel "Name and email address are required if not a client"

I'm getting an error as "Name and email address are required if not a client" while running the below mentioned code.

Find below the Controller Code:

class UserController extends Controller
{

public function insertform(){
    return view('test');
    }

    public function create(){
        $user=Whmcs::AddClient([
            'firstname' => Input::get('firstname'),
            'lastname' => Input::get('lastname'),
            'email' => Input::get('email'),
            'address1' => Input::get('address1'),
            'city' => Input::get('city'),
            'state' => Input::get('state'),
            'postcode' => Input::get('postcode'),
            'country' => Input::get('country'),
            'phonenumber' => Input::get('phonenumber'),
            'password2' => Input::get('password2'),

        ]);
        return $user;
    }
 }

Find below the route code:

Route::get('insert', 'UserController@insertform');
Route::post('create', 'UserController@create')->name('user.create');

The blade file is given below

<div id="content" class="app-content" role="main">
<div class="app-content-body ">


<div class="bg-light lter b-b wrapper-md">
<h1 class="m-n font-thin h3">Sign up</h1>
</div>
<div class="wrapper-md" ng-controller="FormDemoCtrl">
<div class="row">

<div class="col-sm-12">
  <div class="panel panel-default">
    <div class="panel-heading font-bold">create an account</div>
    <div class="panel-body">
      <form class="bs-example form-horizontal" action=" 
  " method="post">
      <input type = "hidden" name = "_token" value = "<?php echo 
   csrf_token(); ?>">
        <div class="form-group">
          <label class="col-lg-2 control-label">firstname</label>
          <div class="col-lg-6">
            <input type="text" class="form-control" name="firstname" 
            placeholder="Name">

          </div>
        </div>
        <div class="form-group">
          <label class="col-lg-2 control-label">lastname</label>
          <div class="col-lg-6">
            <input type="text" class="form-control" name="lastname" 
             placeholder="Name">

          </div>
        </div>
        <div class="form-group">
          <label class="col-lg-2 control-label">Email</label>
          <div class="col-lg-6">
            <input type="email" class="form-control" name="email" 
            placeholder="Email">
          </div>
        </div>
        <div class="form-group">
          <label class="col-lg-2 control-label">address1</label>
          <div class="col-lg-6">
            <input type="text" class="form-control" name="address1" 
           placeholder="Subject">
          </div>
        </div>
        <div class="form-group">
          <label class="col-lg-2 control-label">city</label>
          <div class="col-lg-6">
            <select class="form-control" name="city">
            <option value="-- Select --">-- Select --</option>
                <option value="Coimbatore">Coimbatore</option>
                <option value="Chennai">Chennai</option>
            </select>

          </div>
        </div>
        <div class="form-group">
          <label class="col-lg-2 control-label">state</label>
          <div class="col-lg-6">
            <select class="form-control" name="state">
            <option value="-- Select --">-- Select --</option>
            <option value="Tamilnadu">Tamilnadu</option>
            <option value="Andhra">Andhra</option>
            <option value="Karnataka">Karnataka</option></select>
          </div>
        </div>

         <div class="form-group">
          <label class="col-lg-2 control-label">country</label>
          <div class="col-lg-6">
            <select class="form-control" name="country">
            <option value="-- Select --">-- Select --</option>
            <option value="India">India</option>
            <option value="China">China</option>
            <option value="Australia">Australia</option></select>
          </div>
        </div>

        <div class="form-group">
          <label class="col-lg-2 control-label">postcode</label>
          <div class="col-lg-6">
            <input type="text" class="form-control" name="postcode" 
 placeholder="postcode">
          </div>
        </div>

  <div class="form-group">
          <label class="col-lg-2 control-label">phonenumber</label>
          <div class="col-lg-6">
            <input type="text" class="form-control" name="phonenumber" 
            placeholder="phonenumber">
          </div>
        </div>
        <div class="form-group">
          <label class="col-lg-2 control-label">password</label>
          <div class="col-lg-6">
            <input type="password" class="form-control" name="password2" 
            placeholder="password">
          </div>
        </div>
        <div class="form-group">
          <div class="col-lg-offset-2 col-lg-10">
            <button type="submit" class="btn btn-sm btn- 
            success">Login</button>
          </div>
        </div>

      </form>
    </div>
  </div>
 </div>
</div>


</div>

When I run the above code I'm getting an error as below:

{"result":"error","message":"Name and email address are required if not a client"}

suggest me a solution to solve this and post the data in laravel.



via Chebli Mohamed

lundi 16 avril 2018

Display a table that contains the list of technicians who have the selected tarificationtache

I have 4 tables: metier , tache, technicien and tarificationtache with a many to many relationship and in the pricing table I have the following fields id, tache-id, tariff and relation done on intermediate table technicien_tarificationtache technicien_id,tarificationtache_id

with this code I select a metier then i get the list of taches in relation with that metier already selected and then the list of tarificationtache in relation with the tache selected and now i would like to display in a table list of technicians in relation with tarificationtache selected.But no technician is displayed when i select tarificationtache. Could you please help me with this?

create.blade.php

@extends('Layouts/app')
@extends('Layouts/master')
@section('content')
<!--  jQuery -->
<script 
src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"> 
</script>
<script type="text/javascript">
var getTachesByMetierUrl = "";
var getAdresseByClientUrl = "";
var getTarificationsByTacheUrl = "";
var getTechniciensByTarificationUrl = " 
";

function getAdresseByClient(val) {
    if(val.length>0) {
        var client_id = val;
        $.get(getAdresseByClientUrl+'/'+client_id,function(res) {
            var html = '<option value="">-Select-</option>' ;
            $.each(res.adresses,function(index,item) {
                html+='<option 
value="'+item.id+'">'+item.code_postal+'</option>';
            });
            $('#adresses').html(html);

        });
    }
}


function getTachesByMetier(val) {
    if(val.length>0) {
        var metier_id = val;
        $.get(getTachesByMetierUrl+'/'+metier_id,function(res) {
            var html = '<option value="">-Select-</option>' ;
            $.each(res.taches,function(index,item) {
                html+='<option 
  value="'+item.id+'">'+item.libelle_tache+'</option>';
            });
            $('#taches').html(html);

        });
    }
}
function getTarificationsByTache(val) {

    if(val.length>0) {
        var tache_id = val;
        $.get(getTarificationsByTacheUrl+'/'+tache_id,function(res) {
            var html = '<option value="">-Select-</option>' ;
            $.each(res.tarifications,function(index,item) {
                html+='<option 
value="'+item.id+'">'+item.tarif+'</option>';
            });
            $('#tarifications').html(html);

        });
    }
}

function getTechniciensByTarification(val) {
    if(val.length>0) {
        var tarificationtache_id = val;




            $.get(getgetTechniciensByTarificationUrl+'/'+tarificationtache_id,function(res) {      

            var html = '<option value="">-Select-</option>' ;
            $.each(res.technicien,function(index,item) {
                html+='<option 
value="'+item.id+'">'+item.technicien_id+'</option>';
            });
            $('#technicien').html(html);

        });
    }
}

 </script>
 @if(count($errors))
 <div class="alert alert-danger" role="alert">
    <ul>
        @foreach($errors ->all() as $message)
            <li></li>
        @endforeach
    </ul>
</div>
@endif
<div class="container">
<div class="row"></div>
<div class="col-md-10">
    <h1>Ajout Intervention</h1>
    <form action=" " method="post">
        
        <div class="form-group">
            <label for="client">Client</label>
            <select onchange="getAdresseByClient(this.value)" 
  name="client_id" id="client" 
  class="form-control">
                <option value="">-Select-</option>
                @foreach($client as $t)
                    <option value="">
                        
                    </option>
                @endforeach
            </select>
        </div>


        <div class="form-group">
            <label for="">date intervention</label>

            <input class="form-control" type="date" id="example-date- 
   input" name 
   ="date_intervention" value="">
        </div>

        <div class="form-group">
            <label for="">description</label>
            <input type="text"  name ="description" class="form- 
  control"value=" 
  ">
        </div>


        <div class="form-group">
            <label for="">duree_prevu</label>
            <input class="form-control" type="datetime-local"  name 
="duree_prevu" value=" 
  ">
        </div>
<div class="form-group">
            <div class="col-md-12">
            <div class="col-md-4">
            <label>Metier: </label>
            <select onchange="getTachesByMetier(this.value)" 
style="width: 200px"    
class="productm form-control" id="metiers">
           <option value="">-Select-</option>
                @foreach($metiers as $t)
                    <option value="">
                        
                    </option>
                @endforeach
            </select>
        </div>

        <div class="col-md-4">
            <label>tache: </label>
            <select onchange="getTarificationsByTache(this.value)" 
  style="width: 200px" 
  class="productname form-control" name="tache" id="taches">
            <option value="">-Select-</option>
            </select>
        </div>

        <div class="col-md-4">
            <label>tarification: </label>
            <select 
  onchange="getTechniciensByTarification(this.value)" style="width: 200px" 
  class="productname form-control" name="tarification_id" 
  id="tarifications">
            <option value="">-Select-</option>
            </select>
        </div>

        <div class="col-md-4">
                    <label>technicien: </label>
                    <select style="width: 200px" class="productname 
   form-control" 
   name="technicien_id" id="technicien">
                        <option value="">-Select-</option>
                    </select>
                </div>


 </div>
 </div>

 </div>
 </div>
 </div>
 <link 


href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"
 rel="stylesheet">

<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap- 
datepicker/1.5.0/css/bootstrap- 
datepicker.css" rel="stylesheet">

<script 
src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"> 
</script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap- 
datepicker/1.5.0/js/bootstrap- 
datepicker.js"></script>
@endsection

route.php

Route::get('/techniciensbytache/{tache_id}',         
'TechnicienController@getTechniciensByTache');

model.php

public function techniciens()
{
return $this- >belongsToMany 
('App\technicien','technicien_tarificationtache' 
       ,'tarificationtache_id','technicien_id');
}



via Chebli Mohamed

vendredi 13 avril 2018

Laravel return empty relationship on model when condidtion is true

I have a model where I want to return a empty value when a condition happens, but when I try to get the model:

Model::with('shop')->find(id);

I get this error:

"Call to a member function addEagerConstraints() on null"

This is the code I'm trying:

public function shop(){
    if(true) {
        return null;
    }
    return $this->belongsTo('App\Models\Shop');
}

How is the proper way to return nothing when a condition is true on Laravel relationships?



via Chebli Mohamed

jeudi 12 avril 2018

Store/Check/Get/List Cookie in Laravel 5.1

I just store a cookie into the queue

Cookie::queue('session', $response['session'], 3);

When I try to list all the cookies in the queue, I got an empty array

dd(Cookie::getQueuedCookies()); // I got empty array --->  []


if(Cookie::has('session')) {
    $session = Cookie::get('session');
}

What did I miss ?



via Chebli Mohamed

set the session timeout for specific session

I'm using Laravel 5.1

I want store a certain sesssion, and set it's lifetime to 3 mins only.

Session::put('session', $response['session']);

I know I can set that in here, app/config/session.php

'lifetime' => 3, // = 3 minutes

But the goal here to not mess with the main configurarion of the session of the entire app. I want to set the sesssion timeout for that one.

Something like this maybe

Session::put('session', $response['session'], 3);


Questions

How would one go about and do this ?


I'm open to any suggestions at this moment.

Any hints/suggestions / helps on this be will be much appreciated!



via Chebli Mohamed

mercredi 11 avril 2018

How to pass dynamic data inside model dialogue box in laravel

Find below the code in blade file :

 @foreach($value['products']['product'] as $key)


    <tr role="row">
      <td  class="sorting_desc" tabindex="0" aria- 
      controls="DataTables_Table_0" rowspan="1" colspan="1" aria- 
      label="Rendering engine: activate to sort column ascending" aria- 
      sort="descending"></td>
      <td  class="sorting" tabindex="0" aria-controls="DataTables_Table_0" 
      rowspan="1" colspan="1"
       aria-label="Browser: activate to sort column ascending">


       <a href="" style="color:#23b7e5" data-toggle="modal"
        data-target="#myModal"> - </a>
       </td>
      <td  class="sorting" tabindex="0" aria-controls="DataTables_Table_0" 
      rowspan="1" colspan="1" aria-label="Platform(s): activate to sort 
      column ascending"> - </td>
      <td  class="sorting" tabindex="0" aria-controls="DataTables_Table_0" 
      rowspan="1" colspan="1" aria-label="Platform(s): activate to sort 
      column ascending"> </td>
      <td class="sorting" tabindex="0" aria-controls="DataTables_Table_0" 
       rowspan="1" colspan="1" aria-label="Engine version: activate to sort 
       column ascending"></td>
      <td  class="sorting" tabindex="0" aria-controls="DataTables_Table_0" 
       rowspan="1" colspan="1" aria-label="Engine version: activate to sort 
       column ascending">
      <label class="checkbox-inline">
      <input type="checkbox" checked data-toggle="toggle">Auto Renew
      </label>
      </td>

     </tr>
     <!-- Modal -->
     <div class="modal fade" id="myModal" role="dialog">
     <div class="modal-dialog-lg">

     <!-- Modal content-->
     <div class="modal-content">
     <div class="modal-header">

      <button type="button" class="close" data-dismiss="modal">&times; 
      </button>
      <h4 class="modal-title"><b> -  
      </b></h4>
    </div>
    <div class="modal-body modal-header">
      <p>Domain Name - </p>
    </div>

    <div class="row" style="padding-top:20px;">
  <div class="col-lg-6">
          <a href="" class="block panel padder-v bg-primary item" >
            <span class="text-white font-thin h1 block text-center"></span>
            <p class="text-center text-muted customFont" >Email Accounts</p>

          </a>
        </div>
       <div class="col-lg-6"  style="padding-left:20px;"><a href="" 
       class="block panel padder-v bg-info item">
            <span class="text-white font-thin h1 block text-center"></span>
            <p class="text-muted text-center customFont">Addon Domain</p>

          </a>
        </div>
  </div>


    <div class="row">
  <div class="col-lg-6">
          <a href="" class="block panel padder-v bg-info item" >
            <span class="text-white font-thin h1 block text-center"></span>
            <p class="text-center text-muted customFont" >Add Sub Domain</p>

          </a>
        </div>
     <div class="col-lg-6"  style="padding-left:20px;"><a href="" 
     class="block panel padder-v bg-primary item">
            <span class="text-white font-thin h1 block text-center"></span>
            <p class="text-muted text-center customFont">change Primary 
      Domain</p>

          </a>
        </div>
  </div>

  </div>

</div>

         <!-- my modal closed -->
         @endforeach

In the blade file in the below mentioned code I'm getting the data displayed correctly but inside the modal dailogue I'm getting the same name for different groupname. Suggest me a solution to rectify this issue.

        <a href="" style="color:#23b7e5" data-toggle="modal"
        data-target="#myModal"> - </a>

For modal dailogue I have used the below code:

     <div class="modal-header">

      <button type="button" class="close" data-dismiss="modal">&times; 
      </button>
      <h4 class="modal-title"><b> -  
      </b></h4>
      </div>

Find below the route code:

Route::get('clientlayout.main.myservices','MyServicesController@show');

Controller Code is given below:

class MyServicesController extends Controller
{

public function show(){
    $value = Whmcs::GetClientsProducts([]);

    return view('clientlayout.main.myservices',compact('value'));
}

}



via Chebli Mohamed

lundi 9 avril 2018

Laravel 5.1 Sync user to other users

I build a Laravel app. In table users I have 2 kinds of users - one user is restaurants and another user is restaurant stuff.

What I exactly need?

I want to sync user (res stuff) to user (restaurant). Is that possible or I need to move the restaurant to the other table and then sync?

I'm looking just for the idea and is that possible?

What is the difference between the user in the same table is admin field - res users have value '999' at admin column and res stuff has value '1' at admin column.



via Chebli Mohamed

dimanche 8 avril 2018

Blade's OR statement always echoing default

I have a code that was working fine in PHP 5. But I updated my system and now I'm using PHP 7. The problem happens in every Blade code that uses or statement and the variable is not directly read from the object. In this situation, Blade always echoes the default value.

For example:



Result in PHP 5:

Santa Catarina

Result in PHP 7:

-

I'm using Laravel 5.1 and all the data stored in DB is the same for both results. Any ideas?



via Chebli Mohamed

vendredi 6 avril 2018

Laravel 5.1, passing my ID

I'm trying to pass an ID of a past and insert it into another database.

I got a page with shows posts like this

/posts/{id}

. From there on i want to add a comment section, so i got my form set up like this:

<form method="POST" action="/posts//comments">

(When i inspect the code, it inserts the right id and the "" spot.

inside my routes.php i got the folling route:

Route::post('/posts/{post}/comments', 'CommentsController@store');

and inside CommentsController.php i got the following

    public function store(Post $post)
{
    Comment::create([

        'body' => request('body'),
        'post_id' => $post->id 
    ]);

    return back();
}

When ever i try to add a comment i get this error:

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'post_id' cannot be null

When i change my code from CommentsController.php to this:

'post_id' => "2"

it works fine (but the comment will always be added at post with ID 2) I can't seem to find out why my id wont go trough.

Anny help with this?



via Chebli Mohamed

How to call multiple methods or controllers to a same route in laravel

Find below the controller code with two methods and suggest me how to call these two methods in the same route or whether I have to create two different controllers for the same page(route).

class TicketController extends Controller
{
    public function show(){
    $results=Whmcs::GetTickets([

    ]);
    return view('clientlayout.main.index',compact('results'));
}

    public function set(){
    $test=Whmcs::GetInvoices([

    ]);
    return view('clientlayout.main.index',compact('test'));
}

}

Find below the route file..

  Route::get('clientlayout.main.index','TicketController@show');

  Route::get('clientlayout.main.index','TicketController@set');

Find the code in the blade file and after running this I'm getting an error as undefined index:Results.

  @foreach($results['tickets']['ticket'] as $key)

  
  @endforeach



  @foreach($test['invoices']['invoice'] as $value)

  
  @endforeach

When I run these two foreach loops in a different blade file it executes correctly..But I need these two results to be viewed in the same file.. So suggest me a solution to view both tickets and invoices in the same index page...



via Chebli Mohamed

jeudi 5 avril 2018

Laravel 5.5 : Get mongodb documents between specific date range

Following is the structure of Mongo-DB document:

{
   _id : 'some id',
   message : 'some message',
   createdTime : ISODate('2018-03-08T08:01:46.000Z')
 }

I want to get documents in specific date range, my code is as following:

 $results = Messages::whereBetween(
                             'createdTime', array(
                                 "2018-4-1",
                                 "2018-4-4"
                             )
                         )->get();
        return $results;

but the code is not working, kindly guide me how can I achieve it.



via Chebli Mohamed

mercredi 4 avril 2018

Identify Route's Group in Middleware

My ultimate objective is to limit accesses to the group of routes by validating permissions provided to the user.

These target 'group of routes' have ONE COMMON PARENT GROUP and may have zero or more sub-groups, such that, if access to these target 'group of routes' is permitted/accessible to the user then, all its sub-route groups are also accessible to the user.

To achieve this, I believe I need to differentiate these target group of routes by any uniqueString/parameter in middleware, which is indeed answered here.

But, I want to generalize this further, by applying middleware to common SINGLE PARENT GROUP of all these target group of routes and identify these target group of routes by any means in the middleware.

So, my question is how do I identify/differentiate these target group of routes in the middleware? Is there any way to do so?



via Chebli Mohamed

How to I specify Tinker to use a different database connection?

I have two database connections. One for my application and another for testing. In my ..\config\database.php

         'mysql' => [
            'driver'    => 'mysql',
            'host'      => env('DB_HOST', 'localhost'),
            'database'  => env('DB_DATABASE', 'forge'),
            'username'  => env('DB_USERNAME', 'forge'),
            'password'  => env('DB_PASSWORD', ''),
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => '',
            'strict'    => false,
        ],

        'testing' => [
            'driver'    => 'mysql',
            'host'      => env('DB_TEST_HOST', 'localhost'),
            'database'  => env('DB_TEST_DATABASE', 'forge'),
            'username'  => env('DB_TEST_USERNAME', 'forge'),
            'password'  => env('DB_TEST_PASSWORD', ''),
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => '',
            'strict'    => false,
        ],

I am able to change the database connection in seeding using

php artisan db:seed --database=testing

I wanted to use tinker for the connection 'testing' but unable to change it. Is there any way to change the database connection for tinker similar with database seeding?



via Chebli Mohamed

lundi 2 avril 2018

PHP Laravel. What are the changes in this code that media searches by id, but in url it shows slug? Please help me to solve this routes error

Query :

Due to this below code url looks like : /downloadpage/34 I want to make url seo friendly like : /downloadpage/slug

In table 'media' there is a column - slug

How to change in this code that media searches by id, but in url it shows slug?

routes.php file :

Route::get('/downloadpage/{id}', [
    'as' => 'downloadpage', 'uses' => 'DownloadController@index'

DownloadController.php file :

public function index($id){
    $images   = DB::table('media')->where("id", "=", $id)->get();
    $popular  = DB::table('media')->orderBy('count_download', 'DESC')->take(5)->get();
    $mostlike = DB::table('media')->orderBy('count_like', 'DESC')->take(5)->get();
    $alsolike = DB::table('media')->orderByRaw("RAND()")->where("id", "!=", $id)->take(3)->get();
    $settings = Setting::first();
    $previous = DB::table('media')->where('id', '<', $id)->max('id');
    $next     = DB::table('media')->where('id', '>', $id)->min('id');
    $imgshare = DB::table('media')->where("id", "=", $id)->first();
    return view('download.downloadpage', ['images'=>$images , 'popular'=>$popular, 'mostlike'=>$mostlike, 'alsolike'=>$alsolike, 'settings'=>$settings, 'previous'=>$previous, 'next'=>$next, 'imgshare'=>$imgshare]);
}



via Chebli Mohamed

Can I use laravel dusk package in Laravel 5.1 project?

There are few functions that are found in Laravel Dusk package but cannot find in Jeffrey Way's "Integrated" package. Can I require Laravel Dusk for my Laravel version 5.1? Is it mandatory to upgrade the project to Laravel 5.4?



via Chebli Mohamed