lucasvrm

Experience

2,875

0 Best Reply Awards

  • Member Since 3 Years Ago
  • 14 Lessons Completed
  • 0 Favorites

2nd October, 2015

lucasvrm started a new conversation Finding Social Referrer In Http Request Data • 2 years ago

Hello there!

I am using Analytics Measurement Protocol hits (https://developers.google.com/analytics/devguides/collection/protocol/v1/) to track my links that redirect to 3d party websites. I don't know where to find the social referrer information in the http request to send it to Measurement Protocol.

To access the http request info, I am simply using

dd($request);

Here (http://hew.to/U77Mi) you can see an example of all the http request's data that I have access.

If you want to click the link on twitter, do it from my twitter page https://twitter.com/lucasmaia001

Does anyone know where the social referrer info is?

25th September, 2015

lucasvrm left a reply on Queued Jobs • 2 years ago

@sid405 I am using a VPS now... So I could install supervisord and everything is working just great!

Thanks for the reply!

lucasvrm left a reply on How To Make Queue:listen Running All The Time • 2 years ago

@henrique I am using a vps now and I managed to install supervidord. It is working properly... I did not test amazon sqs yet... I am using database queue driver...

22nd September, 2015

lucasvrm left a reply on Queued Jobs • 2 years ago

@sid405 Hello!

I am testing amazon SQS... Do you know how to make queue:listen or queue:work running all the time in it?

lucasvrm left a reply on How To Make Queue:listen Running All The Time • 2 years ago

@henrique É possível utilizar o Amazon SQS ao invés do iron.io?

20th September, 2015

lucasvrm started a new conversation Tracking Issue • 3 years ago

Hi there!

I have an url shortener app (built just for learning purposes) and I want to develop a tracking solution that will track all access to the shortened url's.

When a user clicks on a shortened url provided by my app, or access it directly, my app receives that request, searches in the database for the matching original url and then redirects the user to that url.

Example:

I want to track some parameters every time a user clicks on a shortened url or access it directly.

I read about Google Measurement Protocol but, in order to use it, I would have to check every required parameters and the parameters I want to track and then send them to Google Analytics servers. But I don't want to do that...

Does anyone have any idea or know another option to accomplish what I want?

18th September, 2015

lucasvrm left a reply on Queued Jobs • 3 years ago

Hello @sid405 ! I managed to solve my issue...

But now I am struggling to resolve another issue...

I want to create a Scheduler to run a php artisan command: queue:work

My website is hosted on a shared host service and I can´t make queue:listen to run all the time.

Can you help me?

lucasvrm left a reply on How To Make Queue:listen Running All The Time • 3 years ago

@henrique Oi Henrique! Sou brasileiro também! Você saberia me dizer se é possível utilizar o Laravel Envoy para criar uma tarefa que sempre deixe o queue:listen rodando?

O meu servidor de hospedagem (webhostface) só permite que os cron jobs sejam executados uma vez a cada 15 minutos. Minha idéia é rodar um cron job a cada minuto. É possível conseguir isso usando o Laravel Envoy?

Eu estou aprendendo a programar, há três meses atrás não sabia programar nada em PHP, muito menos Laravel. Eu contratei esse servidor de hospedagem somente para ter um environment de testes. Não queria rodar nada localmente...

Você tem twitter, whatsapp para trocarmos mais idéias sobre programação? (se você tiver interesse, obviamente)

lucasvrm started a new conversation How To Make Queue:listen Running All The Time • 3 years ago

I can´t install Supervisor on my shared host server...

I read the Laravel´s 5.1 documentation (Task Scheduling and Events) and I read a little about cron jobs.

Which is the best option to make queue:listen running all the time?

I have a job that is queued, and this job grabs a website screenshot and saves it on local disk.

I am only using queued jobs because this function takes too long to run, so the view takes too long to render too.

lucasvrm left a reply on [L5] Working Of Queues • 3 years ago

@toniperic Awesome explanation!!!

I am wondering if there is any way to run queued jobs withouth using

php artisan queue:listen

17th September, 2015

lucasvrm started a new conversation Queued Jobs • 3 years ago

Hello there!

I am trying to create a queued job to grab a screenshot from a url inputed by the user and to save it on local disk.

I was able to create the queue table and to create a job (app/Jobs).

I know this is very trivial, but I didn´t find much content about queued jobs on the internet. All of the examples use email sending queued jobs. And, as I don´t have as most as any experience in Laravel, I really did not understand what do I have to do yet.

I searched for lessons and series about this subject here in Laracasts, but I did not find.

Does anyone have some examples or tutorials that could help me? Or does anyone could help me?

I am taking the screenshot and saving it within my LinksController. But this way, the succes web page takes too long to render...

Bellow is my LinksControler.php code:

$hash = Str::random(5);
            $website_to_screenshot = $request->input('hewit');
            $screenshot_name = $hash.'.jpg';
            $preview_path = 'http://hew.to/previews/guests/'.$hash.'.jpg';

            $screenshot = new Screenshot('Z7DiuJauZaZdGFEjrsJgrGJIywZgts1bZiFnAdvfHHrfiePOPD');
            $screenshot->capture($website_to_screenshot);
            $screenshot->store('/home/frgcplql/public_html/hew.to/public/previews/guests/', $screenshot_name);

            $hewed = 'http://hew.to/'. $hash;

            $link = Link::create([

                'url'           => $request->input('hewit'),
                'hash'          => $hash,
                'preview_path'  => $preview_path,

            ]);

            return Redirect::home()->with([
                'hewed'       => $hewed,
                'hash'        => $hash,
            ]);

        }

    }

lucasvrm left a reply on Class 'App\Http\Controllers\Spatie\Browsershot\Browsershot' Not Found • 3 years ago

@_stefanzweifel Owww... I didn´t pay attention to this matter... I am sorry! Already removed the API key!

16th September, 2015

lucasvrm left a reply on Class 'App\Http\Controllers\Spatie\Browsershot\Browsershot' Not Found • 3 years ago

My code is inside a controller...

---some validation---
$hash = Str::random(5);
            $website_to_screenshot = $request->input('hewit');
            $screenshot_name = $hash.'.jpg';
            $preview_path = 'http://hew.to/previews/guests/'.$hash.'.jpg';

            $screenshot = new Screenshot('Z7DiuJauZaZdGFEjrsJgrGJIywZgts1bZiFnAdvfHHrfiePOPD');
            $screenshot->capture($website_to_screenshot);
            $screenshot->store('/home/frgcplql/public_html/hew.to/public/previews/guests/', $screenshot_name);

            $hewed = 'http://hew.to/'. $hash;

            $link = Link::create([

                'url'           => $request->input('hewit'),
                'hash'          => $hash,
                'preview_path'  => $preview_path,

            ]);

            return Redirect::home()->with([
                'hewed'       => $hewed,
                'hash'        => $hash,
            ]);

lucasvrm left a reply on Class 'App\Http\Controllers\Spatie\Browsershot\Browsershot' Not Found • 3 years ago

@thomaskim I gave up trying to use the spatie/browsershot package... Searching the web, I found another package, created and maintained by a laracasts user, @_stefanzweifel . I installed it, I had some issues to run it (obviously!! I am learning php, laravel, composer, etc while coding hahaha). And Stefan was so attentive: he helped me with everything I needed! Every github issue was answered asap!

I am glad that I managed to achieve what I wanted! I just wanted to grab a website screenshot and save it on local disk. I use this screenshot to show a preview of a shortened url. I am building (just for learning purposes) a url shortener app...

But..... I have a problem now and I am quite sure I will learn a lot resolving it... Every time a user shortens a url, the success view takes too long to render, because the app is grabbing the screenshot of that website...

What I want to do is: to take the user to the success page, and to grab the screenshot and save it on local disk, after that... Like a background process...

I searched the web, laracasts and other laravel´s help sites, but I couldn´t find a solution or a way to do that.

Do you know how I can do that?

15th September, 2015

lucasvrm left a reply on Class 'App\Http\Controllers\Spatie\Browsershot\Browsershot' Not Found • 3 years ago

@thomaskim I am using linux.... @sitesense Thanks for the advice...

I think the error might be something about dir permissions... spatie/browsershot uses phantomjs and I saw here http://devdojo.com/video/74 that phantomjs has to be writable in the screenshots folder...

I'll get back to this issue later... Thanks for your help and attention!

As soon as I manage this issue I´ll let you know...

lucasvrm left a reply on Class 'App\Http\Controllers\Spatie\Browsershot\Browsershot' Not Found • 3 years ago

@thomaskim I tested with a very light site (http://www.google.com) and it did not work... I think this is not the problem...

I tested after decreasing the width and height to see if the problem was related to the size of the image but it did not work either...

It was as simple as that to take a quick peack at the code, wasn´t it? hahaha

I am very new to this laravel, php, javascript world...

lucasvrm left a reply on Class 'App\Http\Controllers\Spatie\Browsershot\Browsershot' Not Found • 3 years ago

@thomaskim What do you mean by "your image file doesn't exist"? I am trying to create an image file... This spatie/browsershot package intent is to create screenshots from a specified url address.

Where did you take a quick peack at the code? I´m asking just to learn with you hahaha

lucasvrm left a reply on Class 'App\Http\Controllers\Spatie\Browsershot\Browsershot' Not Found • 3 years ago

@thomaskim I did what you told:

$browsershot = new \Spatie\Browsershot\Browsershot();

But now I get another error:

Whoops, looks like something went wrong.
1/1 Exception in Browsershot.php line 172: could not create screenshot

    in Browsershot.php line 172
    at Browsershot->save('previews/arstechnica-browsershot.jpg') in LinksController.php line 121
    at LinksController->show_all()
    at call_user_func_array(array(object(LinksController), 'show_all'), array()) in Controller.php line 256
    at Controller->callAction('show_all', array()) in ControllerDispatcher.php line 164
    at ControllerDispatcher->call(object(LinksController), object(Route), 'show_all') in ControllerDispatcher.php line 112
    at ControllerDispatcher->Illuminate\Routing\{closure}(object(Request))
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
    at Pipeline->Illuminate\Pipeline\{closure}(object(Request))

@zachleigh yes I registered the service provider...

lucasvrm started a new conversation Class 'App\Http\Controllers\Spatie\Browsershot\Browsershot' Not Found • 3 years ago

Hello there!

I´ve installed a package called spatie/browsershot and I followed the steps showed here https://github.com/spatie/browsershot

But it's not working at all...

I am new to laravel, so probably this is a silly mistake... What I am doing wrong?

function inside a controller

public function create_preview()
    {
        $findhash = Link::where('hash', '=', $hash)->firstOrFail();
    $browsershot = new Spatie\Browsershot\Browsershot();
        $browsershot
            ->setURL($findhash->url)
            ->setWidth('1024')
            ->setHeight('768')
            ->save('previews/'.$findhash->url.'.jpg');

        return view('pages.teste2', [
            'links'             => $links,
            'countlinks'        => $countlinks,
        ]);

    }

composer.json

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": {
        "php": ">=5.5.9",
        "laravel/framework": "5.1.*",
        "guzzlehttp/guzzle": "~6.0",
        "greggilbert/recaptcha": "^2.0",
        "symfony/dom-crawler": "^2.7",
        "fabpot/goutte": "^3.1",
        "pragmarx/tracker": "^1.0",
        "geoip/geoip": "~1.14",
        "spatie/laravel-analytics": "^1.2",
        "roumen/sitemap": "^2.5",
        "ramsey/uuid": "^2.8",
        "intervention/image": "^2.3",
        "spatie/browsershot": "^1.2"
..........

13th September, 2015

lucasvrm left a reply on Laravel Stats Tracker • 3 years ago

@jrean Thanks... I messed up the migration files... It's working now...

lucasvrm started a new conversation Laravel Stats Tracker • 3 years ago

I am using Laravel Stats Tracker (created by Antonio Ribeiro -> https://github.com/antonioribeiro/tracker) to track some info about visitor.

But, when I try to retrieve the information, like the code below, I get QueryException in Connection.php line 636 error.

Laravel Stats Tracker is a great package but it's not well documented. I can't find even a simple how to use guide...

Route::get('/teste', function () {

        $visitor = Tracker::sessions();
        return View::make('pages.teste')->with([
            'visitor' => $visitor,
        ]);
    });

Error

Whoops, looks like something went wrong.

2/2
QueryException in Connection.php line 636:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'hewtotracker.users' doesn't exist (SQL: select * from `users` where `users`.`id` in (0))
in Connection.php line 636
at Connection->runQueryCallback('select * from `users` where `users`.`id` in (?)', array('0'), object(Closure)) in Connection.php line 596
at Connection->run('select * from `users` where `users`.`id` in (?)', array('0'), object(Closure)) in Connection.php line 315
at Connection->select('select * from `users` where `users`.`id` in (?)', array('0'), true) in Builder.php line 1389

Why is Laravel querying users table? My users table is in another database...

Does anyone uses this package? Could someone help me?

I want to retrieve info like:

  • unique pageviews of a given path (or route I really don't know which one is correct)
  • geoip (country, state, city)
  • useragents
  • referers (url, medium, source, search term...)

8th September, 2015

lucasvrm left a reply on How Tocount Every Time A Route Is Called • 3 years ago

Hey guys! I am going to try your solutions...

Meanwhile, I found a way to accomplish what I wanted.

I put the code bellow in my LinksController.php

    /**

    public function handleShortcode( $shortCode )
    {
        // Find the bookmark against the passed shortcode
        $bookmark = $this->bookmark->getLongUrl( $shortCode );

        if ( $bookmark ) {

            $bookmark->clicks = ++$bookmark->clicks;
            $bookmark->save();

            return Redirect::to( $bookmark->url, 302 );
        } else {
            return App::abort( 404 );
        }
    }

This solved my problem!

3rd September, 2015

lucasvrm started a new conversation How Tocount Every Time A Route Is Called • 3 years ago

Hey!

I am totally new to Laravel and I am trying to count every time a specific route is called to track how many users accessed that route.

Could anyone give me a hint where to begin?

I searched for it in the web, but couldn´t find a solution.

Thanks in advance!

lucasvrm left a reply on Can't Use Goutte/guzzle In Controller, Just In Routes.php • 3 years ago

Hi @0xb5f!!! I knew it was a dumb mistake... I am sorry!!!

And thanks a lot!!! It works know!! :))

lucasvrm started a new conversation Can't Use Guzzle In Controller, Just In Routes.php • 3 years ago

Hello there!

I've installed guzzle, domcrawler and goutte just to retrieve basic information of a site.

If I write the code to retrieve the info inside routes.php, it works... If I write in PreviewController.php, it does not work...

I am vey new to Laravel and I am almost sure that I am not instantiating guzzle the right way in PreviewController.php.

routes.php

<?php

use \Goutte\Client;

Route::get('/', function () {
    
        $url_to_traverse = 'http://hew.to';
        $client = new Client();
        $crawler = $client->request('GET', $url_to_traverse);
        $teste = $crawler->filterXPath('html/head/title')->text();
        dd($teste);
}); 

PreviewController.php (I know I should use Eloquent and I can write a more clear code... I am going to do that!)

<?php

namespace App\Http\Controllers;

use Composer\Json\JsonValidationException;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Str;
use Illuminate\Support\Traits\Macroable;
use View;
use DB;
use App\Link;
use App\Goutte\Client;

class PreviewController extends Controller
{
    public function get_the_preview($hash)
    {

        $hash = trim($hash, '+');

        $url_link = DB::table('links')->select('url')->where('hash', '=', $hash)->first();

        $urlto = ($url_link == null) ? $urlto = 0 : $urlto = 1 ;

        if ($urlto == 0){

            abort(404);

        }

        $url_to_traverse = $url_link->url;
        $client = new Client();
        $crawler = $client->request('GET', $url_to_traverse);
        $teste = $crawler->filterXPath('html/head/title')->text();

        $hewer = 'http://hew.to/'. $hash;
        return View::make('preview.preview')->with([

            'hash'          => $hash,
            'hewer'         => $hewer,
            'title'         => $teste,

        ]);

    }
}

What am I doing wrong? I am sure that my mistake is very silly...

2nd September, 2015

lucasvrm left a reply on DB::insert Isn't Inserting Timestamps Automatically • 3 years ago

Thank you guys! @mstnorris @Francismori7

I am learning Laravel step by step... I will look at Eloquent soon!

Thanks again!!!

lucasvrm started a new conversation DB::insert Isn't Inserting Timestamps Automatically • 3 years ago

I use the bellow code to insert data into my database.

DB::insert('insert into links (url, hash) values (?, ?)', [$url, $hash]);

The table has timestamps columns (created_at and updated_at).

But, when I insert data into database using the code above, it's not inserting timestamps automatically.

What am I doing wrong?

1st September, 2015

lucasvrm left a reply on URL Validation • 3 years ago

I managed to do what you told me. Thanks @bobbybouwmann

I passed my regex (you can see it at my last reply) into the rules. I have to create an array to do that.

$regex = '_^(?:(?:https?|ftp)://)(?:\S+(?::\S*)[email protected])?(?:(?!(?:10|127)(?:.\d{1,3}){3})(?!(?:169.254|192.168)(?:.\d{1,3}){2})(?!172.(?:1[6-9]|2\d|3[0-1])(?:.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\x{00a1}-\x{ffff}0-9]-)[a-z\x{00a1}-\x{ffff}0-9]+)(?:.(?:[a-z\x{00a1}-\x{ffff}0-9]-)[a-z\x{00a1}-\x{ffff}0-9]+)(?:.(?:[a-z\x{00a1}-\x{ffff}]{2,})).?)(?::\d{2,5})?(?:[/?#]\S)?$_iuS';

        $rules = array('hewit' => array('required', 'regex:'.$regex));

        $messages = [
            'hewit.required' => 'enter the url you want to hew',
            'hewit.regex' => 'your url have to be a valid url' . "<br/>" . "<span class='val_error_small'>". '(try putting http:// or https:// or another prefix at the beginning)'. "</span>",
        ];

lucasvrm left a reply on Filter Lessons By Major Version • 3 years ago

+1

31st August, 2015

lucasvrm left a reply on URL Validation • 3 years ago

Ok @bobbybouwmann. But how do I use the regex... The expression I want to use is:

_^(?:(?:https?|ftp)://)(?:\S+(?::\S*)[email protected])?(?:(?!(?:10|127)(?:.\d{1,3}){3})(?!(?:169.254|192.168)(?:.\d{1,3}){2})(?!172.(?:1[6-9]|2\d|3[0-1])(?:.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\x{00a1}-\x{ffff}0-9]-)[a-z\x{00a1}-\x{ffff}0-9]+)(?:.(?:[a-z\x{00a1}-\x{ffff}0-9]-)[a-z\x{00a1}-\x{ffff}0-9]+)(?:.(?:[a-z\x{00a1}-\x{ffff}]{2,})).?)(?::\d{2,5})?(?:[/?#]\S)?$_iuS

Do I have to create a Service Provider? What is the best option?

lucasvrm left a reply on URL Validation • 3 years ago

@bobbybouwmann But is this the best way to validate the url? I read a lot about it and there is a lot of doubt out there about this matter.

I want to validate http://, https://, ftp://, all the existent prefixes...

I found this https://gist.github.com/dperini/729294... Do you think this is a good solution?

29th August, 2015

lucasvrm started a new conversation URL Validation • 3 years ago

I am using the url validation built in laravel and PHP (filter_var/FILTER_VALIDATE_URL) but this does not work like I expected.

URL's such as bellow are validated: hp://example.com htt://example.com htts://example.com

So... What is the best way to validate an URL? I am building a URL Shortener for learning purposes and this issue came up.

I am doing step by step and trying to learn the most I can if every one.

Does anyone knows a better way to validate an URL then the filter_var/FILTER_VALIDATE_URL?

I am using Laravel 5.1.10

28th August, 2015

lucasvrm left a reply on My URL Shortener Does Not Work • 3 years ago

Thanks @bobbybouwmann!

I am trying to start small... I have learned a lot since I started using Laravel...

And I found a hobby! I love "to play with it"!

lucasvrm left a reply on My URL Shortener Does Not Work • 3 years ago

@bobbybouwmann In Jeffrey Way URL Shortener Lessons, he used repositories, services, and other stuff... Do you know why?

lucasvrm left a reply on My URL Shortener Does Not Work • 3 years ago

@bobbybouwmann Great! It was a very simple solution... I read the documentation, tried a lot of things but, as I said, I am a newbie...

And what about my code? Should I put everything inside LinksController.php? Or should I put most of the code somewhere else?

Another question: The way I am writing the app, I can't get access to any page in the website, like /contact and /about, because of my routes.php.


<?php

Route::get('/', ['as' => 'home', 'uses' => 'LinksController@create']);
Route::post('/', ['as' => 'hewurl', 'uses' => 'LinksController@store']);
Route::get('{hash}', 'LinksController@get_the_url');
Route::get('/about', ['as' => 'about', 'uses' => 'PagesController@about']);
Route::get('/contact', ['as' => 'contact', 'uses' => 'PagesController@contact']);
Route::post('/contact', ['as' => 'contactFormPost', 'uses' => 'FormController@contactFormPost']);

When I type http://hew.to/about, my route.php use Route::get('{hash}', 'LinksController@get_the_url');

Is there anyway to solve this issue? Of course that is but I really don't have a clue...

lucasvrm left a reply on My URL Shortener Does Not Work • 3 years ago

@bobbybouwmann This way a keep getting an array for $url... So if I try to redirect the user, I can't, because strpos() expects parameter 1 to be string, and I am giving an object.

ErrorException in Str.php line 410: strpos() expects parameter 1 to be string, object given

Is there another way to retrieve the url from database?

lucasvrm started a new conversation My URL Shortener Does Not Work • 3 years ago

I watched the URL Shortener Lessons and I couldn't create the app like Jeffrey did. As I am very new to Laravel and PHP (I started learning 2 months ago, using my spare time to study) I am taking short steps now (I think those Lessons are to advanced for me).

I am trying to create my own URL Shortener app, using my knowledge to create it. And it has been a very good way to study and search about everything about Laravel and PHP.

I managed to create the hashed url and save it to the database, but now I am stuck... I can't use the URL of a specific hash to redirect the user to when he uses the link generated by the app.

Below I am posting my code. Every comment will be very helpfull for me, because I will learn with everyone. And I just want to use this app for learning purposes...

Laravel 5.1.10 My app url: http://hew.to

routes.php

<?php

Route::get('/', ['as' => 'home', 'uses' => 'LinksController@create']);
Route::post('/', ['as' => 'hewurl', 'uses' => 'LinksController@store']);
Route::get('{hash}', 'LinksController@get_the_url');
Route::get('/about', ['as' => 'about', 'uses' => 'PagesController@about']);
Route::get('/contact', ['as' => 'contact', 'uses' => 'PagesController@contact']);
Route::post('/contact', ['as' => 'contactFormPost', 'uses' => 'FormController@contactFormPost']);

LinksController.php

use Composer\Json\JsonValidationException; use Illuminate\Http\Request; use App\Http\Requests; use App\Http\Controllers\Controller; use Illuminate\Support\Facades\Validator; use Illuminate\Support\Facades\Input; use Illuminate\Support\Facades\Redirect; use Illuminate\Support\Str; use Illuminate\Support\Traits\Macroable; use View; use DB;

class LinksController extends Controller {

public function create()
{
    return View::make('links.crlinks');
}

public function store(Request $request)
{

    $url = $request->all();

    $rules =  [
        'hewit' => 'required|url',
    ];

    $messages = [
        'hewit.required' => 'enter the url you want to hew',
        'hewit.url' => 'your url have to be a valid url' . "<br/>" . '(try putting http:// or https:// at the beginning)',
    ];

    $validator = Validator::make($url, $rules, $messages);

    if ($validator->fails()) {
        return Redirect::to('/')
            ->withErrors($validator)
            ->withInput();
    }

    else {

        $url = $request->input('hewit');

        $hash = Str::random(5);
        $hewer = 'http://hew.to/'. $hash;
        DB::insert('insert into links (url, hash) values (?, ?)', [$url, $hash]);

        return Redirect::home()->with([

            'flash_message' => $hewer,
            'hashed'        => $hash,
            'hewer'         => $hewer,

        ]);

    }

}

public function get_the_url($hash)
{

    $get_the_url = DB::select('select url from links where hash = ?', [$hash]);

    $url_link = $get_the_url['0'];

    dd($url_link);
    /*$get_the_url = DB::select('select url from links where hash = ?', [$hash]);
    return Redirect::to($get_the_url['0']);*/

}

}


What am I doing wrong? What should be refactored? Am I on the right direction?

Thanks in advance!

27th August, 2015

lucasvrm left a reply on Redirect::to | Redirect::route • 3 years ago

Thanks @mstnorris. Great help!

lucasvrm started a new conversation Redirect::to | Redirect::route • 3 years ago

I am new to Laravel and PHP and I am a little bit confused about this class Redirect.

Which one should I use: Redirect::to or Redirect::route? Is there any difference between them?

Thanks!

26th August, 2015

lucasvrm left a reply on Redirect::to('/contact')->withInput() Is Not Working • 3 years ago

@thomaskim There is no problem at all!!! You solved my question anyway!!!

lucasvrm left a reply on Redirect::to('/contact')->withInput() Is Not Working • 3 years ago

@bestmomo my post wasn't clear enough! I am sorry!

The redirect was working but the fields were not being populated... So ->withInput was not working.

I am sorry for my mistake!

lucasvrm left a reply on Redirect::to('/contact')->withInput() Is Not Working • 3 years ago

@thomaskim Thank you a lot! It's working but not exactly like you said. I had to set old('contact-name') between {{!! !!}}

<input class="form-control" name="contact-name" type="text" class="form-control" placeholder="type your name" value="{!! old('contact-name') !!}">

lucasvrm left a reply on Redirect::to('/contact')->withInput() Is Not Working • 3 years ago

@extends('layout')

@section('title')

<title>contact us &middot; hew.to</title>

@stop

@section('js-top')

<script src='https://www.google.com/recaptcha/api.js'></script>

@stop

@section('content')

<h1>contact us</h1>
<h4>just send a message.</h4>
<h4>we'll love to hear from you.</h4>
<br/>
@if (count($errors) > 0)
    @foreach ($errors->get('contact-name') as $message)
        <div class="alert alert-danger alert-dismissible" role="alert">
            <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <ul>{!! $message !!}</ul>
        </div>
    @endforeach
    @foreach ($errors->get('contact-email') as $message)
        <div class="alert alert-danger alert-dismissible" role="alert">
            <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <ul>{!! $message !!}</ul>
        </div>
    @endforeach
    @foreach ($errors->get('contact-msg') as $message)
        <div class="alert alert-danger alert-dismissible" role="alert">
            <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <ul>{!! $message !!}</ul>
        </div>
    @endforeach
@endif
<br/>
<div class="row">
    <div class="spaced-row-contact1">
        <div class="col-xs-5">
            <form class="form-horizontal" method="post" action="/contact">
                <div class="form-group">
                    <label for="contact-name">name</label>
                    <input class="form-control" name="contact-name" type="text" class="form-control" placeholder="type your name">
                </div>
                <div class="form-group">
                    <label for="contact-email">email</label>
                    <input class="form-control" name="contact-email" type="email" class="form-control" placeholder="type your email">
                </div>
                <div class="form-group">
                    <label for="contact-msg">message</label>
                    <textarea name="contact-msg" class="form-control" rows="4" placeholder="your message goes here"></textarea>
                </div>
                <!--<div class="form-group g-recaptcha" data-sitekey="6Lf6uQsTAAAAALp038gqzNnLZH7Nrf0elLFXoA-P"></div>-->
                <div class="form-group">
                    <input class="btn btn-primary" type="submit" value="send your message">
                    <input type="hidden" name="_token" value="{!! csrf_token() !!}">
                </div>
            </form>
        </div>
        <div class="col-xs-7">
            <div class="spaced-row-contact">
                <address>
                    <h5>office location</h5>
                    brazil<br/>
                    belo horizonte, minas gerais<br/>
                    50 amoroso costa street. office 204
                </address>
            </div>
            <!-- Responsive iFrame -->
            <div class="Flexible-container spaced-row-contact">
                <iframe width="600" height="450" frameborder="0" style="border:0" src="https://www.google.com/maps/embed/v1/place?q=Rua%20Amoroso%20Costa%2C%2050%20-%20Santa%20Lucia%2C%20Belo%20Horizonte%20-%20MG%2C%20Brasil&key=AIzaSyBZARKYL-ncUqs9ABfxOiOou0Lv7tDFYjg" allowfullscreen></iframe>
            </div>
        </div>
    </div>
</div><!--end of first row -->

@stop

lucasvrm started a new conversation Redirect::to('/contact')->withInput() Is Not Working • 3 years ago

Hello there!

I am new to laravel and I am trying to validate a very simple form. I created the rules, the custom error messages and I can show to the user which mistakes occured.

But Redirect::to('/contact')->withInput() class is not working. I searched for an solution here, at stackoverflow but I coudn't find anyone. I am using Laravel 5.1.10. Below my code.

PagesController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Redirect;
use View;

class PagesController extends Controller
{

    public function index()
    {
       //
    }
    public function create()
    {
        return View::make('pages.index');
    }

    public function about()
    {
        return View::make('pages.about');
    }

    public function contact()
    {
        return View::make('pages.contact');
    }

    //public function contactFormPost(Request $request)
    public function contactFormPost()
    {
       $postData = Input::all();
       $rules =  [
           'contact-name' => 'required|min:2|alpha',
           'contact-email' => 'required|email',
           'contact-msg' => 'required|min:10|max:250',
       ];

       $messages = [
           'contact-name.required' => 'Enter your name',
           'contact-name.min' => 'Your name must have at least 2 characters',
           'contact-name.alpha' => 'Your name may only contain letters',
           'contact-email.required' => 'Enter you email',
           'contact-msg.required' => 'Enter your message',
           'contact-msg.min' => 'Your message must have at least 10 characters',
           'contact-msg.max' => 'Your message must have at most 250 characters',
       ];

        $validator = Validator::make($postData, $rules, $messages);

        if ($validator->fails()) {
            // send back to the page with the input data and errors
            return Redirect::to('/contact')->withInput()->withErrors($validator);
        }
}

routes.php

Route::get('/contact', ['as' => 'contact', 'uses' => 'PagesController@contact']);   Route::post('/contact', ['as' => 'contactFormPost', 'uses' => 'PagesController@contactFormPost']);
Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.