samedi 31 mars 2018

How to handle this error : Class App\Http\Controllers\post/ProductController does not exist

Code in the blade file is given as below:

@extends('clientlayout.layouts.master1')
@section('title')
Register
@endsection
@section('content')
<div class="container" style="background-color: #c1bdba;max-width: 100% 
!important;">
<div class="row">
  <div class="offset-lg-2 col-lg-8 col-sm-8 col-8 border rounded main- 
  section"  style="background-color:rgba(19, 35, 47, 0.9);">
  <img src="client/images/decksys.png" alt="." style="margin: 20px 0px 20px 
350px;"> 
    <hr>
    <form class="container" action="/create" id="needs-validation" 
method="post" novalidate>
    <input type = "hidden" name = "_token" value = "<?php echo csrf_token(); 
 ?>">
      <div class="row">
        <div class="col-lg-6 col-sm-6 col-12">
           <div class="form-group">
            <label class="text-inverse custom" 
 for="validationCustom01">First Name
 <span class="req">*</span>
 </label>
<input type="text" name="firstname" class="form-control" 
id="validationCustom01"  placeholder="First name"
value="" required maxlength="25" onKeyPress="return ValidateAlpha(event);" 
style="background-color: rgba(19, 35, 47, 0.4); color:#fff;">
            <div class="invalid-feedback">
              Enter Your Firstname
            </div>
          </div>
        </div>

      </div> 
 </form>
   </div>
   </div>  
   </div>
   @endsection

The Controller code is shown below:

<?php

namespace App\Http\Controllers;

use App\Http\Controllers\ProductController;


use Illuminate\Http\Request;

use DarthSoup\Whmcs\Facades\Whmcs;
use Darthsoup\Whmcs\WhmcsServiceProvider;

class ProductController extends Controller
{
 public function insertform(){
    return view('clientlayout.main.signup');
    } 

  public function insert(Request $request){

    $user = User::create([
        'firstname' => $data['firstname'],
        'lastname' => $data['lastname'],
        'email' => $data['email'],
        'city' => $data['city'],
        'dob' => $data['dob'],
        'password' => bcrypt($data['password']),
    ]);
    Whmcs::create($data->all());
    return redirect($this->create());

    echo "Record inserted successfully.<br/>";
    echo '<a href = "/insert">Click Here</a> to go back.';

    }

    }

The route code is given below and suggest me if any changes has to be made in the route.

Route::get('insert', 'ProductController@insertform');
Route::post('create','post/ProductController@insert');

Suggest me a solution to handle this error - "Product Controller doesn't Exit" and to get the output as follows:

Record inserted successfully



via Chebli Mohamed

mercredi 28 mars 2018

How to show message in Popup without reloading the page in Laravel? I am sending data using CURL

This is dashboard.blade.php My View.

<form class="form-horizontal" role="form" method="post" action="" enctype="multipart/form-data">
   <input type="hidden" name="_token" value="">  
   <div class="row">
    <div class="col-md-6">
            <fieldset style="height: auto;">
                    <legend>Complaint Details</legend>
                    <div class="form-group row">
                            <label class="col-md-6 control-label" for="pnr">PNR/Unreserved Tickets No <span class="errors">*</span>: </label>
                            <div class="col-md-6">          
                                    <input type="text" class="form-control" maxlength="10" name="pnr" id="pnr" placeholder="PNR/Unreserved Tickets No." required>
                            </div>
                    </div>
                 </div>
              </div>
           </form>

This is my DashboardController.php

  public function formSubmit(Request $request){ 
  $data1 = [
        'name'=> $passName,
  ];
   $curl = curl_init();

    curl_setopt_array($curl, array(
        CURLOPT_URL => "xyz.com",
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => "",
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 30,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => "POST",
        CURLOPT_POSTFIELDS =>$data1,
        CURLOPT_HTTPHEADER => array(
            "Content-Type: multipart/form-data",
          ),
    ));

    $response = curl_exec($curl);
    $err = curl_error($curl);

    curl_close($curl);
    if ($err) {
        return redirect()->back()->with('message','Error on submitting form.'); 
    } else {  
            return redirect()->back()->with('message','Thank You for Submitting Complaint');
        }

It is working fine. I am sending the data through CURL in Laravel. I just want to not refresh the page after submitting the Form. I just want to show the Successful message or error message in a popup. When I am submitting the form, It reloads the page. I just don't want to reload the page.

Thanks In Advance.



via Chebli Mohamed

How to search autocomplete with laravel?

I'm trying to do search autocompleete in a taable with laaravel. I've triied to do thiis usiing the code below but nothiing happens....... Could you please help me with this....... Thank you in advance....

route.php

Route::get('/metier', 'MetierController@index');
Route::get('/metier/search', 'MetierController@search');
metiercontroller

public function index()
{
$Listmetier=metier::all();
return view('metier.index',['metier'=>$Listmetier]);
}
public function search(Request $request)
{     
if($request->ajax())
{
$output="";
$metiers=DB::table('metiers')- 
>where('libelle_metier','LIKE','%'.$request->search."%")-
>get();
if($metiers)
{
foreach ($metiers as $key => $metiers) {
$output.='<tr>'.
'<td>'.$metiers->id.'</td>'.
'<td>'.$metiers->libelle_metier.'</td>'.
'</tr>';
 }
 return Response($output);
}
}

index.blade.php

@extends('Layouts.app')
@extends('Layouts.master')
@section('content')
<link rel="stylesheet" type="text/css"     
 ref="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

Liste des Metiers Ajouter Metier

        <head>
        <tr>
            <th>libelle metier</th>
            <th>Action</th>

        </tr>
        </head>
        <body>

        </body>
    </table>

</div>
<script type="text/javascript">
    $('#search').on('keyup',function){
        $value=$(this).val();
        $.ajax({
            type: 'get',
            url : '',
            data : {'search':$value},
            success:function(data){
                console.log(data);
            } 
        });
    }
</script>
</div>
</div>
 @endsection



via Chebli Mohamed

jeudi 22 mars 2018

Replacing values in an array basing on values from another

Having the 2 following arrays:

[
    {"id":1,"value":40},
    {"id":2,"value":30},
]

And:

[
    {"userId":1,"worth":20},
    {"userId":2,"worth":10},
]

What I want to have in the end, is the following result:

[
    {"id":1,"value":20},
    {"id":2,"value":10},
]

So here, I want to replace in the first array, the values with those in the second array, according to the ìd`. I made something like that:

foreach ($array2 as $k => $v) {
    array_filter($array1), function($item) use($value) {
        $item['id'] == $v['userId'] ? $item['value'] = $v['worth'] :$item['value'] = $item['value'];
    });
}

It is working for those given arrays, but if you have arrays with more than 1 million data, it will never be done ! The question is, if there are some PHP functions which can do this hard work?



via Chebli Mohamed

mercredi 21 mars 2018

I am using alaouy/Youtube package on my laravel 5.4 its fetching videos from youtube

I am using alaouy/Youtube package on my laravel 5.4 its fetching videos from youtube but i am getting errors i am a little new to laravel hope you can help me out thank you

// /view

@extends('welcome') 
    @section('content')


       <ul>
           @foreach($videos as $data)
                <div class="well">
                    
               </div>
         @endforeach
     </ul>
  @endsection

 enter code here

// controller

   $videos = Youtube::search($search);

  return view('search',compact('videos'));

i am able to get access to all the data in the object except

//Error Undefined property: stdClass::$videoId (View: C:\Users\derrick\testyoutubeapi\resources\views\search.blade.php)



via Chebli Mohamed

mardi 20 mars 2018

Laravel Queue Mail files

I have been trying to move from directly sending emails, to adding them to Laravel Queue, and I've noticed that if the email contains any files, it does not really like to deal with it.

For example, this example works fine if I was to send the email directly, but it will not if I want to add it to the Queue because it will not serialise the $file variable.

$this->mail->queue('emails.contact-us',compact('data'), function($message) use($files)
    {
        $message->from('email@mail.co.uk', 'Test Subject');
            foreach($files as $file){
                $message->attach($file->getRealPath(),array(
                        'as' => $file->getClientOriginalName(),
                        'mime' => $file->getMimeType()
                ));
            }
    });

If I tried to getFileContents, store all data to a varaible and pass the variable to the Queue, it will create a Job, however instead of the Json payload data that it should produce, it adds 0 to the payload column.

So my question is, has anybody dealt with this situation before? I have thought about adding file temporary, but it does not seem like a good solution.



via Chebli Mohamed

vendredi 16 mars 2018

Laravel Devafactory minify: Ajax Calls do not work after minification

I have a few JS files that are expected to place calls to web server once loaded in client/ browser. To minify, I am using Devafactory/minify package with Laravel 5.1 .

It does good minification of CSS and JS. My question is : However, once JS is minified, it does not place any AJAX call to server. Without minification all calls work fine as expected.

Seeking help!



via Chebli Mohamed

jeudi 15 mars 2018

Laravel-Excel xlsx download request not working

I'm using the Maatwebsite/Laravel-Excel(version 2.1) library in Laravel to download an xls file.

class ControllerApi extends Controller {

     private $excel;

     public function __construct(Excel $excel) {
         $this->excel = $excel;
     }

     public function getXlsFile(Request $request) {
           $this->excel->create("Report2016", function($excel) {

            // Set the title
            $excel->setTitle('My awesome report 2016');

            // Chain the setters
            $excel->setCreator('Me')->setCompany('Our Code World');

            $excel->setDescription('A demonstration to change the file properties');

            $data = [12,"Hey",123,4234,5632435,"Nope",345,345,345,345];

            $excel->sheet('Sheet 1', function ($sheet) use ($data) {
                $sheet->setOrientation('landscape');
                $sheet->fromArray($data, NULL, 'A3');
            });

        })->export("xlsx");
     }
}

enter image description here

enter image description here

Even though the response header seems to be okay, the browser don't download the file.

Anyone knows what I'm doing wrong?

Thanks in advance.



via Chebli Mohamed

Laravel: How to do multiple aggregations in a "has through" relationship in a single query

I have the following tables:

Venues

  • id

Offers

  • id
  • venue_id

Orders

  • id
  • offer_id
  • quantity

Venues can have many offers, and offers can have many orders. This is all modelled in the appropriate eloquent models like so:

class Venue extends Model
{
    public function offers()
    {
        return $this->hasMany(Offer::class);
    }
}

class Offer extends Model
{
    public function orders()
    {
        return $this->hasMany(Order::class);
    }
}

I want to run a single query which allows me to see every venue and the number of orders it has. e.g.

venue_id | number_of_orders
---------------------------
5        | 20
15       | 0
8        | 123

I was easily able to do this using raw SQL like so:

select venues.id, sum(offersGrouped.number_of_orders) as total_number_of_orders
from venues
left outer join (
   select offers.id, offers.venue_id, sum(orders.quantity) as number_of_orders
   from offers
   left outer join orders on offers.id = orders.offer_id
   group by offers.id
) offersGrouped on venues.id = offersGrouped.venue_id
group by venues.id;

However, how can I do the same thing using Eloquent?

I am using Laravel 5.1, but I don't mind if answers uses features from newer versions of Laravel if required.



via Chebli Mohamed

mercredi 14 mars 2018

access query scope method in callback funcation

In Eloquent, I have little complex query, final query i want to achieve is this

     $form = makeQueryConditions
            ->with(array(
                'formFields' => function ($query) use ($dynamicQuestionsKeysAndValues) {

                        // duplicated Query logic
$query->duplicationed($dynamicQuestionsKeysAndValues);
                },
                'conditionalQuestions' => function ($query) use ($dynamicQuestionsKeysAndValues) {

                        //duplicated Query logic
$query->duplicationed($dynamicQuestionsKeysAndValues);

                }
            ))
            ->first();

in this query this logic is duplicated so i am to make query scope for this like this

    public function scopeDuplicationed($query ,$dynamicQuestionsKeysAndValues) 
{
                        $query->leftJoin('dynamic_questions_keys', 'dynamic_questions_keys.form_field_id', '=', 'form_fields.id')
                            ->leftJoin('dynamic_questions_key_values', 'dynamic_questions_keys.id', '=', 'dynamic_questions_key_values.dynamic_questions_key_id');
                        $query->where(function ($formFieldsIsDynamic) use ($dynamicQuestionsKeysAndValues) {
                            $formFieldsIsDynamic->where('form_fields.is_dynamic', '=', 0);
                            $formFieldsIsDynamic->orWhere(function ($formFieldsIsDynamicKeys) use ($dynamicQuestionsKeysAndValues) {
                                $formFieldsIsDynamicKeys->where('form_fields.is_dynamic', '=', 1);
                                $formFieldsIsDynamicKeys->where(function ($formFieldsIsDynamicKey_d) use ($dynamicQuestionsKeysAndValues) {
                                    $formFieldsIsDynamicKey_d->whereNull('dynamic_questions_keys.key');
                                    $formFieldsIsDynamicKey_d->orWhere(function ($formFieldsIsDynamicKey_dd) use ($dynamicQuestionsKeysAndValues) {
                                        foreach ($dynamicQuestionsKeysAndValues as $key => $value) {
                                            $formFieldsIsDynamicKey_dd->orWhere('dynamic_questions_keys.key', ($key));
                                            $formFieldsIsDynamicKey_dd->whereIn('dynamic_questions_key_values.values', ($value));
                                        }
                                    });
                                });
                            });
                        });
                        $query->select(DB::raw('DISTINCT(form_fields.id)'), 'form_fields.*');
}

when i try to access query scope method inside the callback function, it give error scopeDuplicationed method no found.Can any one help me please , how can i pass scopeDuplicationed method in call back function



via Chebli Mohamed

mardi 13 mars 2018

Laravel file cannot be deleted

I am trying to delete a file (a temporary file that I create if my import command fails), which is located under storage/framework/cache/.
I tried to use unlink but always I get an error Text file busy (as I searched, this error is displayed because the file is in use).
I tried also File::delete($fullpath) but doesn't work too (no error, but the file is not removed)
The problem is if I check if the file exists, it is always true (I checked also manually and the file is there).
Here what I made:

$lockfilePath = $this->lockFilePath($uri);// if i display this line, I get /var/www/html/project/storage/framework/cache/filename.lock
if (!file_exists($lockfilePath)) {
    throw new RuntimeException("$uri was not locked. Lockfile not found.");
}
\File::delete($lockfilePath); // I tried also unlink($lockfilePath);

I am working with homestead and Laravel 5.1 (PHP version 5.6).



via Chebli Mohamed

dimanche 11 mars 2018

Create superAdmin middleware in Laravel 5.1

I need to create SuperAdmin middleware in my app called 'master' so I make middleware 'IsMaster' :

<?php

namespace App\Http\Middleware;

use Closure;

class IsMaster
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if (\Auth::user() &&  \Auth::user()->admin == 101) {
            return $next($request);
        }

        return redirect('/auth/logout');
    }
}

so as you can see from the code above if 'admin' field in my 'users' table has value 101 that is MASTER user.

Now I add this to Kernel.php:

protected $routeMiddleware = [
        'auth' => \App\Http\Middleware\Authenticate::class,
        'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
        'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
        'admin' => \App\Http\Middleware\IsAdmin::class,
        'master' => \App\Http\Middleware\IsMaster::class,

    ];

now at AdminController.php I use it like:

class AdminController extends Controller
{

    public function __construct() {
        $this->middleware('master', ['except' => ['getMail']]);
    }

...

when I try to login with master user account I got error:

ReflectionException in Container.php line 741: Class master does not exist

enter image description here

What is a problem here? I really dont see what make the issues...

Also I try: php artisan config:clear, php artisan cache:clear ...



via Chebli Mohamed

Save(Insert ),Update,Delete data from dynamic form Laravel 5.*

Hi i have an dynamic form and i don't know how to update or delete it if i add a new field or if i delete a field .

I have an form with input

    <div class="row">
   <div class=""
       <textarea class="from-control"  name="somename[]" id="field"> 
       </textarea>
{!! $errors->first('somename[]',:message) !!}
</div>
    <button class="btn add-field">add</button>
    <button class="btn remove-field">remove</button>
    <div class=""
          <textarea class="from-control" name="name[]" id="field">
         </textarea>
    {!! $errors->first('name[]',:message) !!}
   </div>
</div>

<div class="row" id="newfield">
    <!-- new textarea -->
</div>

i can add a new field when i save i use foreach

 foreach ($request->somename as  $index => $value) {

    $table=  new TableName;
        $table->name= $request->name[$index];
        $table->somename= $request->root_cause[$index];

    $table->save();
    }

For updating i use:

        $id = $request->id;
 foreach ($request->somename as  $index => $value) {

        $table=  TableName::find($id);
            $table->name= $request->name[$index];
            $table->somename= $request->root_cause[$index];

        $table->save();
        }

And the big problem is:

+----------------------+------------------------+
|some input name 1     | input name 1           |
|----------------------|------------------------|
|some input nam 2      | input name 2           |
|----------------------|------------------------|
|some input name 3     | input name 3           |
+----------------------+------------------------+

If for example i edit this and i delete one field how can i update then the query so that input 3 will be removed from database and after refresh i will get?

+----------------------+------------------------+
|some input name 1     | input name 1           |
|----------------------|------------------------|
|some input nam 2      | input name 2           |
+----------------------+------------------------+

And how to update it or save if for example i change the input field or i add a new one:

+----------------------------+------------------------+
|some  name 1                | name 1                 |
|----------------------------|------------------------|
|some nam 2                  | name 2                 |
|----------------------------|------------------------|
|some name 3                 | name 3                 |
|----------------------------|------------------------|
|some  new name 4            | new name 4             |
+----------------------------+------------------------+



via Chebli Mohamed

vendredi 9 mars 2018

How to download and store and then upload drop box shared image in laravel?

I am trying to write a script to upload bulk product from excel sheet which contain product name, price and images. But the images are actually the dropbox image share link.

Now my question is how i can download those image from the drop box url, save them in my server storage and then upload the image url to my database?

Currently for the excel sheet reading i am using Maatwebsite/Laravel-Excel

Generic code for my upload is like this

public function productUpload(Request $request){
    if($request->hasFile('products')){
        $path= $request->file('products')->getRealPath();
        $data = Excel::load($path)->get();
        if($data->count()){
            foreach ($data as $key => $value) {

                //download the image create thumbain and  store to /images/product/thumbnail folder and get the link,
                $thumbnail = //here will be the path for the thumbnaul

                //Original image
                $original = ;
                $data['original']= $original;
                $data['thumbnail']=$thumbnail;
                $data['name']=$value->name;
                $data['price']= $value->price;
                Product::create($data);
            }

            return redirect()->back()->with('success','Product has been uploaded');
        }
    }
}

The image url that is in the excel sheet is like this one https://www.dropbox.com/s/x2tbsy49sraywvv/Ruby12.jpg?dl=0

This file has been removed at this point , but i hope this will give some idea. Can anyone please help me out. Thanks



via Chebli Mohamed

Aws-Sdk-Php version 2, Custom ending point is made as virtual Host instead of path style

I am trying to set a custom endpoint to test some features locally

$aws = $aws = \AWS::factory(array(
            'endpoint' => "localhost:4572"
        ));
        $this->s3 = $aws->get('s3');

But it is giving this error at the time to put images in the server with this wrong url:

//mybucket.localhost:4572/img.jpg

When it should be like this:

http://localhost:4572/mybucket/img.jpg

public function putFileObjectsTo(array $array)
    {
        $targetBucket = self::$BUCKET;
        $batch = array();
        foreach ($array as $value) {
            $path = $value['path'];
            $targetKeyname = $value['targetKeyname'];
            $batch[] = \Guzzle\Service\Client('putObject', array(
                'Bucket' => $targetBucket,
                'Key' => $targetKeyname,
                'SourceFile' => $path,
                'ACL' => 'public-read',
                'CacheControl' => 'max-age=15552000',
                'ContentType' => 'image/jpeg',
                'MetadataDirective' => 'REPLACE'
            ));
        }
        $this->s3->execute($batch);
    }



via Chebli Mohamed

mercredi 7 mars 2018

Laravel routes with slash /

I use Laravel 5.1.

at route I have:

Route::get('/getVoucherRld', 'LiveController@getVoucherRld');

Route::get('/test/getVoucherRld', 'TestController@getVoucherRld');

both getVoucherRld functions are the same but when I try to run then with ajax

function from LiveController works fine but function at TestController just retunr me white screen?

I think the issue is with the route but why? Does anyone have the same issue?



via Chebli Mohamed

How to redirect login plus previous URL in laravel

                                        Laravel 5.1

I'm trying to build this functionality for every method in my controller. And this is very unpractical to do and very difficult to maintain. How can I set this that is when I registered an auth middleware in a specific route then it will redirect into a login page together with the URL that trying to view/visit.

Example:
URL: public/users

If this URL will try to visit by an unauthenticated user, then the user will be redirected to a url like public/login?url=http://localhost/myproject/public/users

Then After the user loggedin successfully, the user then will be redirected into http://localhost/myproject/public/users

What I have now: (But I think not a good one to use)

public function getLoginURL(){
    if(!Input::get('location-login')){
        // URL is not set, redirect user to home.
        return redirect('/');
    }

    if(auth()->check()){
        // User is logged in. Go the specified URL (depends on the middleware of the url (route))
        return redirect()->to(Input::get('location-login'));
    }

    if(!auth()->check()){
        // Redirect user to a login with the URL provided
        return view('pages::auth.login.url');
    }
}



via Chebli Mohamed

How to add item to an array inside a collection in Laravel

I have a Laravel Request object (collection) and there is an array inside this (address array) I want to add a item to this array. I tried $request->address['state'] = 'test'; and following error occurred.

Indirect modification of overloaded property Illuminate\Http\Request::$address has no effect

Here is the request collection

I want to add a item like highlighted in this img



via Chebli Mohamed

dimanche 4 mars 2018

Laravel 5.1 dont receive JWT token from Dingo API

I use Laravel 5.1 + Dingo API + JWT token. My route is:

$api = app('Dingo\Api\Routing\Router');

$api->version('v1', function($api) {

$api->post('authenticate', 'App\Http\Controllers\AuthenticateController@authenticate');
$api->post('logout', 'App\Http\Controllers\AuthenticateController@logout');
$api->get('token', 'App\Http\Controllers\AuthenticateController@getToken');
$api->get('test', 'App\Http\Controllers\BitemsController@test');

});

$api->version('v1', ['middleware' => 'api.auth'], function ($api) {

    $api->get('authenticated_user', 'App\Http\Controllers\AuthenticateController@authenticatedUser');
    $api->get('getvoucher', 'App\Http\Controllers\BitemsController@index');
    $api->post('/store', 'App\Http\Controllers\BitemsController@store');
    $api->put('/update/{key}', 'App\Http\Controllers\BitemsController@update');

});

Now when I run at Postman to get token everything is fine, so I get:

{
    "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOjExMDIsImlzcyI6Imh0dHBzOi8vYXBwLmRpbmVhbmRnaWZ0LmNvbS9hcGkvYXV0aGVudGljYXRlIiwiaWF0IjoxNTIwMjAxMzYwLCJleHAiOjE1MjAyMDQ5NjAsIm5iZiI6MTUyMDIwMTM2MCwianRpIjoiNlhTZWdPRllpaGZNWk5sSSJ9.f71ReEY_3I2-uj-7PJNBxbHhO8C50XP5kbShrnmZ8Ig"
}

but now I want to retrieve auth user and I have function protected by middleware, but I get:

{
    "message": "Failed to authenticate because of bad credentials or an invalid authorization header.",
    "status_code": 401,
    "debug": {
        "line": 113,
        "file": "/home/dgadmin/public_html/test/vendor/dingo/api/src/Auth/Auth.php",
        "class": "Symfony\\Component\\HttpKernel\\Exception\\UnauthorizedHttpException", ... ETC...

What is a problem here and how to solve this issue?

Interesting when I make the call like :

https://app.example.com/api/authenticated_user?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOjExMDIsImlzcyI6Imh0dHBzOi8vYXBwLmRpbmVhbmRnaWZ0LmNvbS9hcGkvYXV0aGVudGljYXRlIiwiaWF0IjoxNTIwMjAxMzYwLCJleHAiOjE1MjAyMDQ5NjAsIm5iZiI6MTUyMDIwMTM2MCwianRpIjoiNlhTZWdPRllpaGZNWk5sSSJ9.f71ReEY_3I2-uj-7PJNBxbHhO8C50XP5kbShrnmZ8Ig

then everything is fine... but when I send token as Authorization header with Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOjExMDIsImlzcyI6Imh0dHBzOi8vYXBwLmRpbmVhbmRnaWZ0LmNvbS9hcGkvYXV0aGVudGljYXRlIiwiaWF0IjoxNTIwMjAxMzYwLCJleHAiOjE1MjAyMDQ5NjAsIm5iZiI6MTUyMDIwMTM2MCwianRpIjoiNlhTZWdPRllpaGZNWk5sSSJ9.f71ReEY_3I2-uj-7PJNBxbHhO8C50XP5kbShrnmZ8Ig then I got the 401 error from above...

Why Laravel won't accept authorization header with my token?

I try to add .htaccess file:

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

    RewriteEngine On



    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteRule ^ - [E=HTTPS_AUTHORIZATION:%{HTTPS:Authorization}]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]




</IfModule>

as you can see I add RewriteRule ^ - [E=HTTPS_AUTHORIZATION:%{HTTPS:Authorization}] but nothing happened

How to solve this?



via Chebli Mohamed

Root Security Issue

simple question :if you make post route and try to access it from google chrome it give me No Message error example :

Route::post('/Login', 'User@Login');

localhost/Login

if i access it from Postman as post request it give what i want

if i access it from Postman as get request

or

if i access it from GoogleChrome (" which is Get Request ")

it return No message error

what i want to redirect any one try to access any route as get to 404notfound page

attached image for the error enter image description here



via Chebli Mohamed

samedi 3 mars 2018

Can't send email with laravel 5.1 + gmail

I'm having troubles sending e-mails via a Laravel 5.1 application using gmail.

Here is my config file :

 <?php
    return [
            'driver' => 'sendmail',
            'host' => 'smtp.gmail.com',
            'port' => 578,
            'from' => array('address' => 'adresse@gmail.com', 'name' => 'Something'),
            'encryption' => 'tls',
            'username' => 'someaddress@gmail.com',
            'password' => '****',
            'sendmail' => '/usr/sbin/sendmail -bs',
            'pretend' => false,

    ];

Allowing less secure apps to access your account is turned on.

What config shall I use ?



via Chebli Mohamed

BadMethodCallException in Controller.php line 283: Method [] does not exist

I move my app from a server to another server, so from an IP address to other. I everything copy/paste including database, users ...

Now when I type example.com/venue/1 everything works fine, but when I type example.com/dng/1 app return me the error:

BadMethodCallException in Controller.php line 283: Method [dng] does not exist.

I run command php artisan route:list and everything is fine so all method including /dng{id} is here...

WHen I run php artisan route:cache I got: enter image description here

What is a problem? At old server everything was fine...



via Chebli Mohamed

vendredi 2 mars 2018

Laravel : Config value set at runtime is shared among concurrent requests

I am using laravel 5.1. I have read that if any config is set at runtime, its new value is available only in the current request. However, I am experiencing that this is not true for concurrent requests. If two concurrent requests are setting and getting configs then config value gets shared. How can this be avoided?



via Chebli Mohamed

Update on "user" and "technicien" with one to one connection

I have two tables user and technician with one to one connection, technician inherits from user. After editing technician information through edit form and saving no update happens on tables user and technician. and no errors as well.Here is my code Could anyone help me with this, please ? Thank you for the attention you give to my question and for not judging me.

Controllers

public function edit($id)
{
    $technicien=technicien::find($id);
    $user = $technicien->user;
    return view('technicien.edit',['technicien'=>$technicien])->with('user',$user);
}

public function update(Request $request, $id)
{
    // do some request validation

    $technicien=technicien::find($id);
    $technicien->update($request->all());
    $technicien->user->update($request->get('user'));
    $user->nom = $request->update('nom');

    return redirect('/technicien');
    }

View

 @extends('Layouts/app')
 @extends('Layouts.master')
 @section('content')
<div class="container">
    <div class="row">
        <div class="col-md-10">
            <h1>Modifier Technicien</h1>
        <form action="" method="update">
        
        


             <div class="form-group">
            <label for="nom">Nom</label>
            <input id="nom" type="text" class="form-control" name="user[nom]" value="" >
        </div>
        <div class="form-group">
            <label for="prenom">Prenom</label>
            <input id="prenom" type="text" class="form-control" name="user[prenom]" value="" >
        </div>
        <div class="form-group">
            <label for="prenom">Email</label>
            <input id="prenom" type="text" class="form-  control" name="user[email]" value="" >
        </div>

        <div class="form-group">
            <label for="">moyenne Avis</label>
            <input type="text"  name="moyenne_avis" class="form-control" value ="" >
        </div>
        <div class="form-group">
            <label for="">Etat Technicien</label>
            <input type="text"  name="actif" class="form-control" value ="" >
        </div>

        <div class="form-group">
            <input type="submit" value="enregistrer"        class="form-control btn btn-primary">
        </div>
            </div>




        </form>
    </div>
</div>
@endsection

Route.php

Route::get('/technicien/{id}/edit', 'TechnicienController@edit'); Route::patch('/technicien/{id}', 'TechnicienController@update')->name('technicien.update');



via Chebli Mohamed

update on "user" and "technicien" whith one to one connection

I have two tables user and technicien with one to one connection, technicien inherits from user. After editing technicien information through edit form and saving no update happens on tables user and technicien. and no errors as well.Here is my code Could anyone help me with this please ? Thank you

controllers

public function edit($id)
{
$technicien=technicien::find($id);
$user = $technicien->user;
return view('technicien.edit',['technicien'=>$technicien])-
>with('user',$user);
}

public function update(Request $request, $id)
{
// do some request validation

$technicien=technicien::find($id);
$technicien->update($request->all());
$technicien->user->update($request->get('user'));
$user->nom = $request->update('nom');

return redirect('/technicien');
}

View

@extends('Layouts/app')
@extends('Layouts.master')
@section('content')
<div class="container">
<div class="row">
    <div class="col-md-10">
        <h1>Modifier Technicien</h1>
    <form action="" method="update">
    
    


         <div class="form-group">
        <label for="nom">Nom</label>
        <input id="nom" type="text" class="form-control" name="user[nom]" value="" >
    </div>
    <div class="form-group">
        <label for="prenom">Prenom</label>
        <input id="prenom" type="text" class="form-control" name="user[prenom]" value="" >
    </div>
    <div class="form-group">
        <label for="prenom">Email</label>
        <input id="prenom" type="text" class="form-control" name="user[email]" value="" >
    </div>

    <div class="form-group">
        <label for="">moyenne Avis</label>
        <input type="text"  name="moyenne_avis" class="form-control" value ="" >
    </div>
    <div class="form-group">
        <label for="">Etat Technicien</label>
        <input type="text"  name="actif" class="form-control" value ="" >
    </div>

    <div class="form-group">
        <input type="submit" value="enregistrer" class="form-control btn btn-primary">
    </div>
        </div>

    </form>
</div>
</div>
@endsection

route.php

Route::get('/technicien/{id}/edit', 'TechnicienController@edit');
Route::patch('/technicien/{id}', 'TechnicienController@update')-
>name('technicien.update');



via Chebli Mohamed

jeudi 1 mars 2018

Class 'Anand\LaravelPaytmWallet\PaytmWalletServiceProvider' not found

I tried to install Laravel Paytm Wallet plugin from AnandSiddharth using composer on my GoDaddy deluxe shared hosting server. I was unable to install it in laravel folder. I copied the vendor files from my desktop to the server and updated config/app.php page in providers and alias category. Then the web server throws an error

Class 'Anand\LaravelPaytmWallet\PaytmWalletServiceProvider' not found

I tried to install it in server home folder and move to vendor but it is showing the same error. The composer.json file gets updated. You can see the screenshots. Any working solution will be helpful. Thanks.

error Log

FatalThrowableError in ProviderRepository.php line 146:
Class 'Anand\LaravelPaytmWallet\PaytmWalletServiceProvider' not found in ProviderRepository.php line 146
at ProviderRepository->createProvider('Anand\LaravelPaytmWallet\PaytmWalletServiceProvider') in ProviderRepository.php line 114
at ProviderRepository->compileManifest(array('Illuminate\Foundation\Providers\ArtisanServiceProvider', 'Illuminate\Auth\AuthServiceProvider', 'Illuminate\Broadcasting\BroadcastServiceProvider', 'Illuminate\Bus\BusServiceProvider', 'Illuminate\Cache\CacheServiceProvider', 'Illuminate\Foundation\Providers\ConsoleSupportServiceProvider', 'Illuminate\Routing\ControllerServiceProvider', 'Illuminate\Cookie\CookieServiceProvider', 'Illuminate\Database\DatabaseServiceProvider', 'Illuminate\Encryption\EncryptionServiceProvider', 'Illuminate\Filesystem\FilesystemServiceProvider', 'Illuminate\Foundation\Providers\FoundationServiceProvider', 'Illuminate\Hashing\HashServiceProvider', 'Illuminate\Mail\MailServiceProvider', 'Illuminate\Pagination\PaginationServiceProvider', 'Illuminate\Pipeline\PipelineServiceProvider', 'Illuminate\Queue\QueueServiceProvider', 'Illuminate\Redis\RedisServiceProvider', 'Illuminate\Auth\Passwords\PasswordResetServiceProvider', 'Illuminate\Session\SessionServiceProvider', 'Illuminate\Translation\TranslationServiceProvider', 'Illuminate\Validation\ValidationServiceProvider', 'Illuminate\View\ViewServiceProvider', 'App\Providers\AppServiceProvider', 'App\Providers\AuthServiceProvider', 'App\Providers\EventServiceProvider', 'App\Providers\RouteServiceProvider', 'Anand\LaravelPaytmWallet\PaytmWalletServiceProvider')) in ProviderRepository.php line 60
at ProviderRepository->load(array('Illuminate\Foundation\Providers\ArtisanServiceProvider', 'Illuminate\Auth\AuthServiceProvider', 'Illuminate\Broadcasting\BroadcastServiceProvider', 'Illuminate\Bus\BusServiceProvider', 'Illuminate\Cache\CacheServiceProvider', 'Illuminate\Foundation\Providers\ConsoleSupportServiceProvider', 'Illuminate\Routing\ControllerServiceProvider', 'Illuminate\Cookie\CookieServiceProvider', 'Illuminate\Database\DatabaseServiceProvider', 'Illuminate\Encryption\EncryptionServiceProvider', 'Illuminate\Filesystem\FilesystemServiceProvider', 'Illuminate\Foundation\Providers\FoundationServiceProvider', 'Illuminate\Hashing\HashServiceProvider', 'Illuminate\Mail\MailServiceProvider', 'Illuminate\Pagination\PaginationServiceProvider', 'Illuminate\Pipeline\PipelineServiceProvider', 'Illuminate\Queue\QueueServiceProvider', 'Illuminate\Redis\RedisServiceProvider', 'Illuminate\Auth\Passwords\PasswordResetServiceProvider', 'Illuminate\Session\SessionServiceProvider', 'Illuminate\Translation\TranslationServiceProvider', 'Illuminate\Validation\ValidationServiceProvider', 'Illuminate\View\ViewServiceProvider', 'App\Providers\AppServiceProvider', 'App\Providers\AuthServiceProvider', 'App\Providers\EventServiceProvider', 'App\Providers\RouteServiceProvider', 'Anand\LaravelPaytmWallet\PaytmWalletServiceProvider')) in Application.php line 507
at Application->registerConfiguredProviders() in RegisterProviders.php line 17
at RegisterProviders->bootstrap(object(Application)) in Application.php line 203
at Application->bootstrapWith(array('Illuminate\Foundation\Bootstrap\DetectEnvironment', 'Illuminate\Foundation\Bootstrap\LoadConfiguration', 'Illuminate\Foundation\Bootstrap\ConfigureLogging', 'Illuminate\Foundation\Bootstrap\HandleExceptions', 'Illuminate\Foundation\Bootstrap\RegisterFacades', 'Illuminate\Foundation\Bootstrap\RegisterProviders', 'Illuminate\Foundation\Bootstrap\BootProviders')) in Kernel.php line 222
at Kernel->bootstrap() in Kernel.php line 117
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 87
at Kernel->handle(object(Request)) in index.php line 53

config/app.php

Anand\LaravelPaytmWallet\PaytmWalletServiceProvider::class,



via Chebli Mohamed

Laravel : no errors and no update on database happens after saving the edit

I have two tables user and technicien with one to one connection. After editing technicien information through edit form and saving no update happens on database and no errors as well.Here is my code Could anyone help me with this please ? Thank you

controllers

public function edit($id)
{
    $technicien=technicien::find($id);
    $user = $technicien->user;
    return view('technicien.edit',['technicien'=>$technicien])->with('user',$user);
}

public function update(Request $request, $id)
{
    // do some request validation

    $technicien=technicien::find($id);
    $technicien->update($request->all());
    $technicien->user->update($request->get('user'));
    $user->nom = $request->update('nom');

    return redirect('/technicien');
}

View

@extends('Layouts/app')
@extends('Layouts.master')
@section('content')
<div class="container">
    <div class="row">
        <div class="col-md-10">
            <h1>Modifier Technicien</h1>
        <form action="" method="update">
        
        


             <div class="form-group">
            <label for="nom">Nom</label>
            <input id="nom" type="text" class="form-control" name="user[nom]" value="" >
        </div>
        <div class="form-group">
            <label for="prenom">Prenom</label>
            <input id="prenom" type="text" class="form-control" name="user[prenom]" value="" >
        </div>
        <div class="form-group">
            <label for="prenom">Email</label>
            <input id="prenom" type="text" class="form-control" name="user[email]" value="" >
        </div>

        <div class="form-group">
            <label for="">moyenne Avis</label>
            <input type="text"  name="moyenne_avis" class="form-control" value ="" >
        </div>
        <div class="form-group">
            <label for="">Etat Technicien</label>
            <input type="text"  name="actif" class="form-control" value ="" >
        </div>

        <div class="form-group">
            <input type="submit" value="enregistrer" class="form-control btn btn-primary">
        </div>
            </div>




        </form>
    </div>
</div>
@endsection

route.php

Route::get('/technicien/{id}/edit', 'TechnicienController@edit');
Route::patch('/technicien/{id}', 'TechnicienController@update')-
>name('technicien.update');



via Chebli Mohamed

Laravel :error when updating the database after editing data

I have two tables table "technician" and table "user" with a connection one to one and I have a form through which I edit the technician information. When I save the changes I get an error and the update doesn't work.Here is my form my code and a screenshot of the error Thank you in advance.

route.php

Route::get('/technicien/{id}/edit', 'TechnicienController@edit');
Route::patch('/technicien/{id}', 'TechnicienController@update')-
>name('technicien.update');

edit.php

@extends('Layouts/app')
@extends('Layouts.master')
@section('content')
<div class="container">
    <div class="row">
        <div class="col-md-10">
            <h1>Modifier Technicien</h1>
        <form action="" method="update">
        
        


             <div class="form-group">
            <label for="nom">Nom</label>
            <input id="nom" type="text" class="form-control" name="user[nom]" value="" >
        </div>
        <div class="form-group">
            <label for="prenom">Prenom</label>
            <input id="prenom" type="text" class="form-control" name="user[prenom]" value="" >
        </div>
        <div class="form-group">
            <label for="prenom">Email</label>
            <input id="prenom" type="text" class="form-control" name="user[email]" value="" >
        </div>

        <div class="form-group">
            <label for="">moyenne Avis</label>
            <input type="text"  name="moyenne_avis" class="form-control" value ="" >
        </div>
        <div class="form-group">
            <label for="">Etat Technicien</label>
            <input type="text"  name="actif" class="form-control" value ="" >
        </div>

        <div class="form-group">
            <input type="submit" value="enregistrer" class="form-control btn btn-primary">
        </div>
            </div>




        </form>
    </div>
</div>
@endsection

controller1.php

public function edit($id)
{
    $technicien=technicien::find($id);
    $user = $technicien->user;
    return view('technicien.edit',['moyenne_avis'=>$technicien],
    ['actif'=>$technicien],['user_id'=>$technicien])->with('user',$user);
}

controller2.php

public function update(Request $request, $id)
{
    // do some request validation

    $technicien=technicien::find($id);
    $technicien->update($request->all());
    $technicien->user->update($request->get('user'));
    return redirect('technicien');
}

enter image description here



via Chebli Mohamed

Laravel : Property [nom] does not exist on this collection instance

i have two tables user and technicien with one to one connection. When i edit a technicien using my form "Modifier Techicien" below i want the form to be autofilled with current information from both tables user and technicien. At this time the form is autofilled with only information from technicien. Could anyone help me with this please ?

enter image description here

controller

public function edit($id)
{
    $technicien=technicien::find($id);
    $users = user::orderBy('id', 'asc')->get();
    return view('technicien.edit',['moyenne_avis'=>$technicien],
['actif'=>$technicien],['user_id'=>$technicien])-
>with('users',$users);
}

public function update(Request $request, $id)
{
    // do some request validation
    $technicien=technicien::find($id);
    $technicien->update($request->all());
    return redirect('technicien');
}

edit.blade.php

@extends('Layouts/app')
@extends('Layouts.master')
@section('content')
<div class="container">
    <div class="row">
        <div class="col-md-10">
            <h1>Modifier Technicien</h1>
        <form action="" method="post">
        
        


            <div class="form-group">
                <label for="">Nom</label>
                <input id="nom" type="text" class="form-control" name="nom" value="" >
            </div>
            <div class="form-group">
                <label for="">Prenom</label>
                <input id="nom" type="text" class="form-control" name="nom" value="" >
            </div>

            <div class="form-group">
                <label for="">moyenne Avis</label>
                <input type="text"  name ="moyenne_avis" class="form-control" value ="" >
            </div>
            <div class="form-group">
                <label for="">Etat Technicien</label>
                <input type="text"  name ="actif" class="form-control" value ="" >
            </div>



            <div class="form-group">

                <input type="submit" value = "enregistrer" class="form-control btn btn-primary">
            </div>
        </form>
    </div>
</div>
@endsection



via Chebli Mohamed