Krlinhos

Krlinhos

Member Since 4 Years Ago

Experience Points
2,585
Total
Experience

2,415 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed
0
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start-engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

Level 1
2,585 XP
Oct
10
1 week ago
Activity icon

Started a new Conversation Behat Test Not Overwrite .env Values

Hello,

I have a project with a .env file and other .env.behat The problem is when I run the tests the values for variables are .env values instead of .env.behat I have realized that if I have a variable in .env.behat and not in .env this value is as expected, but if I have the variable in both files, the value always is from .env file

behat.yml:

default: 
    extensions: 
        Laracasts\Behat\ServiceContainer\BehatExtension: 
            env_path: .env.behat 
...

.env:

VARIABLE_ONE=A

.env.behat:

VARIABLE_ONE=B VARIABLE_TWO=C

when I run the test VARIABLE_ONE worths A instead of B, and VARIABLE_TWO worths C

Someone has some idea??

Thanks!

May
26
2 years ago
Activity icon

Started a new Conversation Select(DB::Raw) Return Only One Result

Hello!

I'm trying to get in one query of various joins. I have one table (fields_values) that have multiple row for each row from the main table (leads). I've found a query solution, it works well when executing in SequelPro, but when I execute it in Laravel only retrieve the first row... After various proof I have found that problem is these lines:

->addSelect(\DB::raw('MAX(CASE WHEN F.RowNum=1 THEN F.value END) as Field1'))
->addSelect(\DB::raw('MAX(CASE WHEN F.RowNum=2 THEN F.value END) as Field2'))

Because when I comment these lines the query return all rows.

Does anyone know why this happens?

Thanks! :)

Complete query:

\DB::table('leads as L')
->join('prizes as P', 'L.prize_id', '=', 'P.id', 'left outer')
->join(\DB::raw('(SELECT field_lead.*, if(@lead_id<>lead_id,@rn:=0,@rn), @lead_id:=lead_id, @rn:=@rn+1 as RowNum FROM field_lead, (Select @rn:=0,@lead_id:=0) as t ORDER BY lead_id) as F'), function($join)
{
    $join->on('L.id', '=', 'F.lead_id');
})
->select('L.id')

->addSelect(\DB::raw('MAX(CASE WHEN F.RowNum=1 THEN F.value END) as Field1'))
->addSelect(\DB::raw('MAX(CASE WHEN F.RowNum=2 THEN F.value END) as Field2'))

->addSelect('L.email')
->addSelect('L.exchange')
->addSelect('L.created_at as date')
->addSelect('P.name as prize')
->get();

PS.- I'm working around a new code and new DB layout in order to reboot the project into version 2. As I finish this new version, I need to correct this query in the actual project.

Dec
11
2 years ago
Activity icon

Replied to How Can I Retrieve All Registers From Pivot Table, With Softdeleted

Thanks SaeedPrez, I will use this solution for moment :)

Activity icon

Replied to How Can I Retrieve All Registers From Pivot Table, With Softdeleted

Hi @SaeedPrez!

With this line, I get this error:

BadMethodCallException in Builder.php line 2123: Call to undefined method Illuminate\Database\Query\Builder::withTrashed()

Activity icon

Started a new Conversation How Can I Retrieve All Registers From Pivot Table, With Softdeleted

Hello!

I have a model Bono with softdeleted, User model and bono_user table pivot (Relation many to many).

I want to make $user->bonos and retrieve all bonos (regardless of if bono is now softdeleted or not).

For example Mike has 2 bonos (Bono A, and Bono B). But in some time the admin deleted (soft) Bono B. When I try to retrieve Mike's Bono, I get only data from non deleted bonos, but I want to retrieve all data bonos.

How can I get all?

Thanks!

Oct
27
2 years ago
Activity icon

Replied to Cant Found Class Validator In My Service

I found the solution!

The problem was in my setUp method definition... I missed parent::setUp();

Thanks!

Activity icon

Replied to Cant Found Class Validator In My Service

Sorry I dont undertand you

Activity icon

Replied to Cant Found Class Validator In My Service

Hello @InaniELHoussain ,

If I use this, I get an Error: RuntimeException: A facade root has not been set.

Activity icon

Started a new Conversation Cant Found Class Validator In My Service

Hello! I'm Trying make a Service

<?php 

namespace App\Services;

use Illuminate\Http\Request;

use App\Exceptions\FailRegisterException;
use App\Exceptions\InvalidFieldsException;

use Validator;

class RegisterService
{
    // use ValidatesRequests;

    public function register(Request $request, $rules)
    {
        $data = $request->all();

            $validator = Validator::make($data, $rules);

             if (!$validator->fails()) {

                    try {
                         $this->store($data);
                    } catch (Exception $e) { 
                        throw new FailRegisterException($e->getMessage(), 400);
                    }       

                    return ['Something'];
             } else {
                    throw new InvalidFieldsException('Invalid fields', 400);
             }
    }

But when I test my RegisterService.php I get an Error: Fatal error: Class 'Validator' not found in...

My RegisterServiceProvider is:

/**
     * Indicates if loading of the provider is deferred.
     *
     * @var bool
     */
    protected $defer = false;

    /**
     * Bootstrap the application services.
     *
     * @return void
     */
    public function boot()
    {
        //
    }

    /**
     * Register the application services.
     *
     * @return void
     */
    public function register()
    {
        $this->bindRegisterService();
    }

    /**
     * Register the application services.
     *
     * @return void
     */
    public function bindRegisterService()
    {
        $this->app->bind('registerService', function($app){
            return new RegisterService();
        });
    }

Why cant found the Validator Class?? :(

May
06
3 years ago
Activity icon

Replied to Get Variable From Closure In Excel Maatwebsite

@jimmck I've fixeeeeeed!! :)

It was problem with chunk method of Maatswebsite library

https://github.com/Maatwebsite/Laravel-Excel/issues/720

Activity icon

Replied to Get Variable From Closure In Excel Maatwebsite

@jimmck I forget quit $filePath when I've copied and pasted from other function. I've removed just it

Activity icon

Replied to Get Variable From Closure In Excel Maatwebsite

@jimmck Nothing... :(

...
try {
            $that = $this;
            $codesInserted = $this->promo->codes()->count();
            $codesInFile = Excel::load($filePath)->get()->count();
            $this->duplicates = false;

            if ($codesInserted < 2000000 && $codesInserted + $codesInFile <= 2000000) {

                // Si hay códigos insertados la query debe comprobar que los nuevos son distintos de los que ya existen.
                if ($codesInserted) {
                    Excel::filter('chunk')->selectSheetsByIndex(0)->load($filePath)->chunk(3000, function($results) use (&$that)
                    {
                        $codesToImport = [];

                        foreach($results as $row)
                        {
                            $code = $row->get('code');
                            if(preg_match('/[\w-]+/', $code)) {
                                array_push($codesToImport, $code);
                            }
                        }

                        if ($this->promo->codes()->whereIn('code', $codesToImport)->count()) {
                            // $this->duplicates = true;
                            $that->setDuplicates(true);
                            echo 'TRUEE';
                        } 
                    }); 
                }

                var_dump($that->duplicates);
                dd($this->duplicates);
...

In screen 'TRUEE', bool(false), bool(false)

I'll write on git maatwebsite repository, maybe there get answers :)

Thank you!

May
05
3 years ago
Activity icon

Replied to Get Variable From Closure In Excel Maatwebsite

Hi @jimmck Sorry for late reply. I've been all day with a friend trying to solve this, but we have not found any way. The truth is I do not know what else I can try... :(

Activity icon

Replied to Get Variable From Closure In Excel Maatwebsite

@jimmck I try $duplicates = $this->duplicates and neither. I dont know why it doesnt work, because in stackoverflow there are post that fix this, but when I try doesnt work :S

Activity icon

Replied to Get Variable From Closure In Excel Maatwebsite

@jimmck thanks I will try and tell you. :)

Activity icon

Replied to Get Variable From Closure In Excel Maatwebsite

@jimmck the $this->promo->codes() works fine. If I debbug and write echo 'something'; results shows something in screen.

...
            if ($this->promo->codes()->whereIn('code', $codesToImport)->count()) {
                 echo 'something';
         $duplicates = true;
            } 
...

I show you all controller:

<?php

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

use App\Agency;
use App\Code;
use App\Promo;
use Excel;

class CodeController extends Controller
{
    private $promo;

    private $user;

    private $duplicates;

    public function __construct() 
    {
        $this->user = \Auth::user();
        $this->middleware('can.edit.promo');    
    }

    /**
     * Muestra el formulario para crear el universo de códigos
     *
     * @param String
     * @return \Illuminate\Http\Response
     */
    public function index($id, Request $request) 
    {
          $this->promo = $request->get('promo');
            $data = [
                'promo' => $this->promo,
            ];

            return view('promo/form-codes', $data);
    }



    /**
     * Muestra el formulario para crear el universo de códigos
     *
     * @param String
     * @param  \Illuminate\Http\Request
     * @return \Illuminate\Http\Response
     */
    public function codesPost($id, Request $request) 
    {        
        $this->promo = $request->get('promo');

        $rules = [
            'method'   => 'in:excel,auto',
            'quantity' => 'required_if:method,auto|digits_between:1,6',
            'file'     => 'required_if:method,excel|mimes:xls,xlsx'
        ];

        $valido = \Validator::make($request->all(), $rules);

        if ($valido->fails()) {
            return response()->json(['status' => 'ko', 'message' => $valido->errors()], 422);
        } else {
            return $this->generateCodes($request);
        }
    }



    /**
     * LLama a la funcion del método específico.
     *
     * @param String
     * @return \Illuminate\Http\Response
     */
    private function generateCodes(Request $request) 
    {    
        if ($request->input('method') == 'auto') {
            return $this->insertCodesAuto($request->input('quantity'));
        } else {
            return $this->insertCodesFromExcel($request->file('file'));
        }
    }

    

    /**
     * Inserta los códigos de manera automática, cogiendolos desde la base de datos Codes.
     *
     * @param String
     * @return \Illuminate\Http\Response
     */
    private function insertCodesAuto($quantity)
    {
        ...
    }


    /**
     * Inserta los códigos desde un excel.
     *
     * @param  \Symfony\Component\HttpFoundation\File\UploadedFile
     * @return \Illuminate\Http\Response
     */
    private function insertCodesFromExcel($file)
    {
        ini_set('max_execution_time', 3000);
        
        if ($file->isValid()) {
            $extension       = $file->getClientOriginalExtension();
            $destinationPath = 'promos/' . $this->promo->id;
            $fileName        = 'codesToImport.'.$extension;
            $filePath        = public_path($destinationPath . '/' . $fileName);

            $file->move($destinationPath, $fileName);
        }
        else {
            return response()->json(['status' => 'ko', 'message' => ['notValid' => ['El archivo no es válido']]], 422);
        }

        try {
            $codesInserted = $this->promo->codes()->count();
            $codesInFile = Excel::load($filePath)->get()->count();
            $this->duplicates = false;

            if ($codesInserted < 2000000 && $codesInserted + $codesInFile <= 2000000) {

                // Si hay códigos insertados la query debe comprobar que los nuevos son distintos de los que ya existen.
                if ($codesInserted) {
                    Excel::filter('chunk')->selectSheetsByIndex(0)->load($filePath)->chunk(1000, function($results) use ($filePath)
                    {
                        $codesToImport = [];

                        foreach($results as $row)
                        {
                            $code = $row->get('code');
                            if($code) {
                                array_push($codesToImport, $code);
                            }
                        }

                        if ($this->promo->codes()->whereIn('code', $codesToImport)->count()) {
                            $this->duplicates = true;
                            echo 'TRUEE';
                        } 
                    }); 
                }

                if ($this->duplicates) {
                    return response()->json(['status' => 'ko', 'message' => ['codeDuplicate' => ['Existen códigos duplicados en el excel que intentas importar.']]], 422);
                }   

                Excel::filter('chunk')->selectSheetsByIndex(0)->load($filePath)->chunk(1000, function($results) use ($filePath)
                {
                    $codesToImport = [];

                    foreach($results as $row)
                    {
                        $code = $row->get('code');
                        if($code) {
                            array_push($codesToImport, ['code' => $code, 'promo_id' => $this->promo->id]);
                        }
                    }

                    Code::insert($codesToImport); 
                });

                \File::delete($filePath);              

                return response()->json(['status' => 'ok', 'message' => 'Los códigos se han insertado.'], 200);
            } else {
                return response()->json(['status' => 'ko', 'message' => ['tableNotEmpty' => ['No puede insertar más códigos.']]], 422);
            }
        } catch (Exception $e) {

            \File::delete($filePath);

            return response()->json(['status' => 'ko', 'message' => ['errorImport' => 'Ha ocurrido un error intentando insertar los códigos.']], 422);
        }
    }
}

In these code, I use $this->duplicates instead variable $duplicates and net pass it by reference. But the result is the same...

Thank four your help @jimmck :)

May
04
3 years ago
Activity icon

Replied to Get Variable From Closure In Excel Maatwebsite

Hi @jimmck. I've tried your solution but doesn't work. I have tried use a private variable class method ($this->duplicates) too and neither works :(

Thanks anyway :)

Activity icon

Started a new Conversation Get Variable From Closure In Excel Maatwebsite

Hello! :)

I'm using Library Excel from Maatwebsite, I need get a variable from closure but when I try it with a reference paramenter not work. Here is my code:

$duplicates = false;
Excel::filter('chunk')->selectSheetsByIndex(0)->load($filePath)->chunk(1000, function($results) use ($filePath, &$duplicates)
 {
          $codesToImport = [];

           foreach($results as $row)
           {
                  $code = $row->get('code');
                   if($code) {
                        array_push($codesToImport, $code);
                   }
           }

            if ($this->promo->codes()->whereIn('code', $codesToImport)->count()) {
                  $duplicates = true;
            } 
}); 

if ($duplicates) {
    doSomething...
}

But always return false, and this is not right...

Any idea?

Thank you!

Apr
21
3 years ago
Activity icon

Started a new Conversation Set TableName On Runtime In Relation HasMany

Hello,

I have two models, one promo.php

class Promo extends Model 
{
    /**
     * The table used by the model.
     *
     * @var string
     */
    protected $table = 'promos';
    
    public function getLeads() {
        return $this->hasMany('\App\Lead');
        }

another lead.php

class Lead extends Model 
{
    /**
     * The table used by the model.
     *
     * @var string
     */
    protected $table = 'leads';
        
    public function getLeads() {
        return $this->belongsTo('\App\Promo');
      }

And the database structure is table_promos and several tables as leads_1, leads_2, leads_3, ... I have read that I can change at runtime the table for the model with the method setTable () But if you want to use Eloquent as follows:

$promo = \App\Promo::find(1);
$leads = $promo->leads();

dd($leads);

But this way I get an error, because there is no table leads, only leads_1, leads_2... Is there any way to change the model leads.php table and put the corresponding tablaName (leads_1, leads_2 ...)?

Thank you!

Apr
11
3 years ago
Activity icon

Started a new Conversation Set And Pass Parameter To Route

Hello! I need to set a dynamic domains in route.php I need get this domain, search if this exist in db, then get its subdomain asociated. I will show you:

    // Setup the host
        $host = \Request::server('HTTP_HOST');
        $domain = preg_replace('/^www\./', '', $host);

    Route::group(['domain' => $domain], function ($domain) {
            $promo = \App\Promo::where('domain', $domain)->first();
        if ($promo) {
                $subdomain = $promo->subdomain;
            Route::get('/',  ['as' => 'play.index', 'uses' => 'PlayController@index'], ['subdomain' => $subdomain]);
            } else {
                return view('errors.400', ['error' => '404', 'message' => 'Promo not found.']); 
            }
    });

But when I try to recieve in my controller the parameter, the controller sais that parameter is missing...

    public function index ($subdomain)
        {
        dd($subdomain);
    } 

In my app there are promos all with a subdomain like promo1.mydomain.com, some of them has a a third's domain www.otherdomain.com, so I need detect this domain and next verify if it has a promo asociate and its subdomain.

thanks!

PS.- Sorry for my inglish...

Apr
06
3 years ago
Activity icon

Replied to Import Excel File With Chunk Method

I had fixed uploading first the file, and next pass to load method the file's path :)

Activity icon

Started a new Conversation Import Excel File With Chunk Method

Hello! I'm trying to import Excel file with library Laravel Excel from Maatwebsite. When I use just

Excel::load(Input::file('archive'), function ($reader) {
    doSomething...
})

All is right, but when I try to implement chunk filter, I get this error:

Serialization of 'Symfony\Component\HttpFoundation\File\UploadedFile' is not allowed

Code with chunk method

Excel::filter('chunk')->selectSheetsByIndex(0)->load($file)->chunk(250, function($results)
 {
    doSomething...
});

Someone has an idea?

Thank you!

Jan
28
3 years ago
Activity icon

Replied to Manage Undefined Routes

Many thanks to both of you!

Activity icon

Started a new Conversation Manage Undefined Routes

Hello,

I have defined all routes that I'll need, so, how can manage other undefined routes? For example:

localhost/other-route localhost/other-route/2 ...

Thanks! :)

Activity icon

Replied to Routes And Wildcard Subdomain

Hi!

Finally I have resolved this so:

Route::group(['domain' => '{subdomain}.'.env('HOST')], function($subdomain) {
    Route::get('/',  ['as' => 'play.index', 'uses' => 'PlayController@index'],  ['subdomain' => $subdomain]);
});

And In my controller recieve parameter $subdomain ;)

Thanks!

Jan
27
3 years ago
Activity icon

Started a new Conversation Routes And Wildcard Subdomain

Hello!

I need create wildcard subdomain. In my routes I have this:

Route::group(['domain' => 'localhost'], function($promo) {
    ....

    any routes;
});


Route::group(['domain' => '{subdomain}.localhost.'], function($subdomain) {
    Route::get('/', 'MyController@function');
});

But I dont know two things:

1.- Can I change localhost por env('HOST') and in .env define HOST=myhost.es? I have tried it but returns errors :S 2.- How can I pass $subdomain to my function in MyController?

Thanks!!

Dec
31
3 years ago
Activity icon

Replied to Add New Method To A Laravel Class

@petrit I dont understand you :(

Activity icon

Replied to Add New Method To A Laravel Class

Hello @bobbybouwmann,

I try to do this:

I have to extend a LengthAwarePaginator Class, with a method setItems(). I need to can set the items retrive from Paginate method

            $data = $players->paginate($limit)->setItems($customPlayer);

So, I need to aggregate this method to LengthAwarePaginator Class.

Activity icon

Started a new Conversation Add New Method To A Laravel Class

Hello!

I need to add method in a laravel's class. Wich is the best practice for that?

Thanks and Happy New Year!

Dec
03
3 years ago
Activity icon

Replied to Same Model Distint Tables

But in MongoDB too?

Activity icon

Replied to Same Model Distint Tables

Hi @deringer, the problem is that in this collection there will be millions of records, so instead I have all of them in same table with a field promo_id to identify each lead that belongs promotion. I think its better a colletion lead each promotion. These collections will be smaller and when the promotions end and erease it, also erease his lead's collection.

Its a bad idea?

Activity icon

Started a new Conversation Same Model Distint Tables

Hello!

I have a Model called Lead with his protected attributes, one of them, collection is leads (his collection in mongodb). But in my app now, I need create severals collection like leads_id, for example; leads_8786hf78, leads_6739t6s7

So, my question is... there is a solution for change the attribute collection when I do this

$lead = new Lead($name_table)

Now I use Schema::create($name_table) and then use DB::class instead eloquent for get an set register from collection..

Thanks

Nov
09
3 years ago
Activity icon

Replied to I Can't Recieve Postfields Data

@jerimiah.short Thanks, but my error was that I wrotte my route bad.. hehehehe thanks anyway! :)

Nov
05
3 years ago
Activity icon

Replied to Collections Method Adding

Great! Thanks!

So, for query builder and collection are methods withe same name, but they works different?

Activity icon

Started a new Conversation Collections Method Adding

Hello,

I have a problem. When I try to get a elements from db, and after I try to make calculate with them, it does not work. I'll show my code to explain better.

$promos = new Promo();
$promos = $promos->where('agency_id', $id);

        $data = [
                'totalPromos' => $promos->count(),
                'totalLeadmo' => $promos->where('type', 'leadmo')->count(),
                'totalConsumo' => $promos->where('type', 'consumo-bill')->count()
                'totalDraft' => $promos->where('state', 'draft')->count()
    ]

When I show on screen the values, totalPromos = 5, totalLeadmo = 3 but totalConsumo = 0 I think that where( ) method being coupled

How can made it?

Thanks

Oct
29
3 years ago
Activity icon

Replied to Prevent Reload Page With Form

Ok! Thanks!

Oct
28
3 years ago
Activity icon

Started a new Conversation Prevent Reload Page With Form

Hello,

I have a view with a form and the csrf hidden field. When I submit the form, works fine, it call a function, it makes something and finally return a view (not make redirecto) So in this new view, if I reload the browser, it try to send one more the datas from form..

Is there a way that prevent it?

thanks!

Oct
21
3 years ago
Activity icon

Replied to I Can't Recieve Postfields Data

Just fix it! :) Sorry, was a little mistake... hehehe

But now, when I print $request->all( ) in api, return { }

Why not recieve fields in the api? :S

I guess that it is for Content-Type, because when in use PostMan, if I choose "x-www-form-urlencoded", so I retrieve, but when choose form-data, not recieve.

I'm trying to set "application/x-www-form-urlencoded" so:

$client = new \GuzzleHttp\Client();

        $response = $client->request('POST', $url, [
            'form_params' => $data,
            'headers' => [
                'Content-Type' => 'application/x-www-form-urlencoded',
            ]
        ]);

But nothing...

Any idea?

thanks!!

Activity icon

Replied to I Can't Recieve Postfields Data

@pmall Hello again!

I'm trying to use guzzle, I have installed it with composer so:

php composer.phar require guzzlehttp/guzzle:~6.0

Next, in my controller I have:

use GuzzleHttp\Client;

And in the function this:

$client = new \GuzzleHttp\Client();


        $response = $client->request('POST', 'http://api.mylocal.es', [
            'form_params' => [
                'field_name' => 'abc',
                'other_field' => '123',
                'nested_field' => [
                    'nested' => 'hello'
                ]
            ]
        ]);

        return $response;

But when execute it, I recieved an error:

FatalErrorException in Router.php line 1223: Class 'Symfony\Bridge\PsrHttpMessage\Factory\HttpFoundationFactory' not found

Can you help me please?

PS.- I had installed guzzle previously for send email with Mandrill, and I had not problems.. So I dont know if it is bad installed or there are something more that I have to do for request.. :(

Oct
19
4 years ago
Activity icon

Replied to I Cant Load View From Other Location

Ok, I'll try again :) thanks!

Activity icon

Replied to I Cant Load View From Other Location

But how can make a new directory in views. When a user create a new promo, I need that crontroller create a new folder with the views for these promo.

Can I create with File::makeDirectory( ) it?

Activity icon

Replied to I Cant Load View From Other Location

@pmall

I asked in another post, how could create directories for storing files. Someone told me that with File::, but I tried it and I got an error with mkdir () and permissions. But with Storage works fine .. so I create the directory storage.

In these directory I save some expecifics views.

Activity icon

Replied to I Cant Load View From Other Location

Just fix it...

view()->addNamespace('promos', storage_path() . '/promos');
Activity icon

Started a new Conversation I Cant Load View From Other Location

Hello,

I have some views save in these path: Project/storage/app/promos/ I try this:

view()->addNamespace('promos', '/storage/app/promos');
return view('promos::nameView');

But I get an error. View['nameView'] not found

What am I doing wrong?

Oct
16
4 years ago
Activity icon

Replied to I Can't Recieve Postfields Data

Ok, I will do :)

thanks!

Activity icon

Replied to I Can't Recieve Postfields Data

Thanks, but I would like to try to resolve it with curl, no other third party library. I wonder what is wrong I have that function :(

Activity icon

Started a new Conversation I Can't Recieve Postfields Data

Hello!

I try to make cURL with post method and postdata so:

private static function curl($url, $method, $postFields = null) {
        $curlHandler = curl_init();

        curl_setopt($curlHandler, CURLOPT_URL, $url);
        curl_setopt($curlHandler, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'X-API-Key:' . env('API_KEY')));
        curl_setopt($curlHandler, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curlHandler, CURLOPT_FRESH_CONNECT, true);

        if ($method == 'POST') {
            curl_setopt($curlHandler, CURLOPT_POST, 1);
            if ($postFields) {
                curl_setopt($curlHandler, CURLOPT_POSTFIELDS, $postFields);
            }
        } elseif (in_array($method, ['PUT', 'PATCH', 'DELETE'])) {
            curl_setopt($curlHandler, CURLOPT_CUSTOMREQUEST, $method);
        }

        $exec = curl_exec($curlHandler);
        curl_close($curlHandler);

        return json_decode($exec);
    }

but when in the function that supposedly recieves the datas, recieves nothing...

public function store(Request $request)
    {    
        return var_dump($request->all());
}

It's empty :(

Someone can help me?

Thanks!!

PD.- postFiel previously in other function I do http_build_query($data, '', '&')

Oct
08
4 years ago
Activity icon

Replied to Path For MakeDirectory

I retrieve this error:

ErrorException in Filesystem.php line 337: mkdir(): Permission denied

Activity icon

Started a new Conversation WhereRaw With Regexp In Mongodb

Hello!

I have search but I dont found the solution... When I search in eloquent whit where condition

Promo::where('name', $name)->first( )

These search is case-insensitive, 'Test' is different to 'test'. I have seen whereRaw, but I dont know how put a regex like...

Promo::whereRaw('name', '/^'. $name. '$/i')->first( )

Someone has the same Issue?

Thanks!