rory

rory

Member Since 1 Year Ago

Experience Points 1,610
Experience Level 1

3,390 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 Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

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

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

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

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    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 Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

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

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

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

02 Oct
7 months ago

rory left a reply on Ajax Not Sending Data To Controller

I tried all the proposed solutions but none worked. I think I should look into routes because the route and the controller are somehow not communicating. All my routes are set on "web" Middleware should I change something here?

01 Oct
7 months ago

rory left a reply on Ajax Not Sending Data To Controller

@ouhare thank you for your answer. I get always the same results. Searching on the web I saw that instead of putting the token as input it should be in header as meta. Do I need to pass then the token along with ajax data? I also realized that input token has no value, just a content.

rory started a new conversation Ajax Not Sending Data To Controller

I'm trying to send data from a form with ajax to the controller. The Ajax is executing but the function in controller not. I do not get any error, I just get the YES! printed but after that nothing happen. Can anyone check what is wrong?

This is the Ajax

$(document).ready(function() {
  $("#sissend").click(function(e){
        e.preventDefault();
        var formdata =  $('#sistrixKw').serializeArray();
        console.log(formdata);

    $.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
    });

    $.ajax({
        url: "/sistrix",
        type: "POST",
        data: {'formdata' : 'formdata', "_token": $('#token').val()},
      
        success: function(){
            console.log("YES!")
            
        },
        
    });     
});

This is the form in the view (in a Modal):

Domain Date This Week Last Week Keywords ammount

This is the function that should receive the data from Ajax but is not:

public function sendtosistrix(Request $request)
 {
        var_dump($request->all());
        exit;
    //do other someth...
26 Sep
8 months ago

rory left a reply on Ajax Post To Controller Give Method Not Allowed

Thanks everybody!!! Now it is working. I can't really check one answer as the right one since all your suggestions were useful to complete the function and avoid the error.

rory left a reply on Ajax Post To Controller Give Method Not Allowed

@tykus sorry this was an error in the question I updated it.

@tykus @aurawindsurfing I'll try both solutions thank you.

rory started a new conversation Ajax Post To Controller Give Method Not Allowed

I'm trying to implement a loading spinner while a controller function is executing. For this, I need to send data from a form(modal) to Ajax and then post these data to controller function, then display the loading spinner until the function is complete. The problem is that I get method not allowed but I can't figure out what I'm doing wrong.

My route:

Route::post('/sist', '[email protected]');

My view:

<div class="modal-body">
                     <form method="post" id="sistKw" name="sistKw" enctype="multipart/form-data">
             
                        <input type="hidden" name="jid" id="jid">
                        <div class="row">
                            <div class="form-group">
                                <label for="domain" class="col-sm-3 control-label">Domain</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="domain" name="domain"        
    value="https://www.blablabla.org">
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="form-group">
                                <label for="date" class="col-sm-3 control-label">Date</label>
                                <div class="col-sm-9">
                                    <label class="radio-inline">
                                        <input type="radio"  id="now" name="week" class="week" value="now" 
      checked> This Week
                                    </label>
                                    <label class="radio-inline">
                                        <input type="radio" id="lastweek" name="week" class="week" 
       value="last week"> Last Week
                                    </label>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="form-group">
                                <label for="kwnum" class="col-sm-3 control-label">Keywords 
       ammount</label>
                                <div class="col-sm-9">
                                    <input  type="number" min="0" class="form-control" id="kwnum" 
        name="kwnum" value="2">
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
<div class="modal-footer">
                    <button type="submit" form="sistrixKw" class="btn btn-primary" id="sissend"          
     value="">Send</button>
                </div>

And this is the jq/Ajax:

$(document).ready(function() { $("#sissend").click(function(){ var jid = $('#jid').val(); var domain = $('#domain').val(); var week = $('.week:checked').val(); var kwnum = $('#kwnum').val();

    $.ajax({
        url: "/sistrix",
        type: "POST",
        data: { 'jid' : 'jid',
                'domain' : 'domain',
                'week' : 'week',
                'kwnum' : 'kwnum',
              },
        DataType: 'JSON',
        success: function(){
            $('#spinner').show();
        }
        //complete:function(){
            //$('#spinner').hide(),
        //}
    });
    //$('#spinner').css('display', 'block');
    //$('#spinner').show();
});
19 Sep
8 months ago

rory started a new conversation Show Loading Spinner While My Controller Execute A Function

Hi! I have a simple question but I can't get how to solve this problem. How do I show a loading spinner in view while my controller executes a function?

18 Sep
8 months ago

rory left a reply on Add Two Foreign Key To Existing Table

Ok, I solved the problem dropping the entire table!

Schema::dropIfExists('siscontents');
    Schema::create('siscontents', function (Blueprint $table) {
        $table->increments('id');
        $table->integer('url_id')->nullable()->unsigned();
        $table->integer('job_id')->nullable()->unsigned();
        $table->foreign('url_id', 'job_id')->references('id', 'job_id')->on('job_urls')- 
         >onDelete('cascade')->onUpdate('cascade');
        $table->string('url')->index();
        $table->text('keywords');
        $table->integer('position')->nullable();
        $table->integer('competition')->nullable();
        $table->integer('traffic')->nullable();
        $table->string('response_status');
        $table->timestamp('created_at')->nullable();
        $table->timestamp('update_at')->nullable();
    });

rory left a reply on Add Two Foreign Key To Existing Table

@tykus

  • yes, I already have the columns for ´´´uri_id´´´ and ´´´job_id´´´.

  • No, there are not such orphaned ids

rory started a new conversation Add Two Foreign Key To Existing Table

I need to add two FK to an existing table, I tried different solutions but none of them worked I always got an error of violation constraint.

These are the migration I attempted:

Schema::table('siscontents', function(Blueprint $table) {
            #$table->dropForeign('siscontents_url_id_foreign');
         $table->foreign('url_id')->references('id')->on('job_urls')->onDelete('cascade')-           
    >onUpdate('cascade');
         $table->foreign('job_id')->references('id')->on('jobs')->onDelete('cascade')-       
    >onUpdate('cascade');
        });


Schema::table('siscontents', function(Blueprint $table) {
            $table->dropForeign('siscontents_url_id_foreign');
            $table->foreign('url_id','job_id')->references('id','id')->on('job_urls','jobs')-    
     >onDelete('cascade')->onUpdate('cascade');
        
     });
05 Sep
8 months ago

rory left a reply on Display A Button After A Function In Controller Is Successfully Executed

@Smally thank you very much for your answer, it does work but it updated all the row in my table. I did not mention in my question that the button should appear only in the row where the enumSTATUS is updated. I tried to do this but it did not work:

In Controller:

    $statusjob = Job_model::findOrFail($jobid);
            //change status
            $statusjob->status = "COMPLETED";
            // Save/update status.
            $statusjob->save();

            return redirect()->back()->with('statusjob', $statusjob);

And then in View

    @if(isset($statusjob))
                <button type="button" class="btn btn-secondary btnsis" href="{{          
                route('siscontent', $item->id) }}">Content</button>
        @endif

rory started a new conversation Display A Button After A Function In Controller Is Successfully Executed

I'm trying to figure it out the best way to display a button in a view after a function in the controller is successfully executed.

I was thinking to return a variable to view and check if this variable is set then display the button, but I'm not sure this is the best way.

Can anyone point me a good solution?

04 Sep
8 months ago

rory left a reply on Php How To Efficiently Loop Over Nested Array?

Thanks, but this will loop only over the first array giving me as result four arrays of one element. What I want is the element inside this arrays. For the moment I made two nested foreach loop but it does not seem to be the best solution.

rory started a new conversation Php How To Efficiently Loop Over Nested Array?

I have this array coming out to a database query. Which is the best way to loop over it?

array(5) { [0]=> array(1) { ["url"]=> string(56) "http://www.blabla.org/65" } [1]=> array(1) { ["url"]=> string(67) "http://www.blabla.org/46247" } [2]=> array(1) { ["url"]=> string(54) "http://www.blabla.org/1234" } [3]=> array(1) { ["url"]=> string(53) "http://www.blabla.org/56789" } [4]=> array(1) { ["url"]=> string(57) "http://www.blabla.org/34456" } }

03 Sep
8 months ago

rory left a reply on Select Table Rows With The Same Foreign Key

I have some problem to understand how the query with model works because the documentation is very dry about it. It does not give examples on how to do a complex query with multiple restrictions as my case require. I also find this discussion which considers the advantages/disadvantages of using Eloquent and query builder (https://stackoverflow.com/questions/38391710/laravel-eloquent-vs-query-builder-why-use-eloquent-to-decrease-performance). I have to say that with Laravel I'm always puzzled about the "best practice"...and it is always hard to find an answer since each Laravel user seems to have his own "best practice".

rory left a reply on Select Table Rows With The Same Foreign Key

Thank you for your answer. Yes, I have the model with relationships. Can I do the query directly with the models?

29 Aug
8 months ago

rory started a new conversation Select Table Rows With The Same Foreign Key

Hi!

I have two tables (Jobs->Urls) with a relation one-to-many. Now I would like to retrieve all the urls_id that have the same jobs_foreign_key. I tried this but it does only deliver the first result, it should deliver a total of 5 ids.

This is my code:

$url_id = \DB::table('job_urls')->select('id')->where('job_urls.job_id', '=', $jobid)->value('id');
28 Aug
8 months ago

rory started a new conversation "Undefined Variable: Errors (View: /var/www/tcc/src/resources/views/partials/flashMessage.blade.php)

I got this error: "Undefined variable: errors (View: /var/www/tcc/src/resources/views/partials/flashMessage.blade.php)

When trying to return a view on API route from Controller in Laravel. How can I pass data that I got from API to my view?

rory started a new conversation Return View On API Route

Hi! I'm trying to return a view on API route but it does not display anything...any suggestion? When I try to return the view from the controller I get: "Undefined variable: errors (View: /var/www/tcc/src/resources/views/partials/flashMessage.blade.php)

This is the API route:

´´´

Route::get('/sistrix', '[email protected]'{
        return view('pages/sistrix');
});

´´´

20 Aug
9 months ago

rory started a new conversation Composer Suddenly Not Found

Hi!

I'm using Laravel and composer for a month and I never had any problem. Now when I attempt to run "composer require spatie/laravel-analytics" I got "composer.phar command not found" what can I do to fix this?

15 Aug
9 months ago

rory started a new conversation Connect Laravel With Third-part API That Requires A API-key

I'm trying to connect Laravel with a third-party API but I'm not sure the documentation about API authentication is right for me. Besides this how should I connect Laravel to the API, where does the API-key go? Can you suggest me a tutorial or point me to the right part in the documentation that can help me doing this step?

rory left a reply on Managing Function Direct In Route

@Vilfago thanks this is exactly how I'm doing it. Now I'm sure that I'm not doing anything wrong.

rory started a new conversation Managing Function Direct In Route

I just start to use Laravel and there is a general question about the good practices that I wish to ask. Until now I preferred to use Routes just to call controller function, like that:

´´´ Route::get('/jobs', '[email protected]'); ´´´ When I look for tutorial or similar I always find that some function logic are directly written in Route like this:

´´´ Route::put('articles/{id}', function(Request $request, $id) { $article = Article::findOrFail($id); $article->update($request->all());

return $article;
 });

´´´

I personally do not like the second way because I found it confusing and unclear, but I wonder if there are any specific reasons to do this.

14 Aug
9 months ago

rory left a reply on "Go Back" To A Route With Certain {id} In The Path.

This worked better:

´´´ \DB::table('job_urls')->select('job_id')->where('job_urls.id', '=', $urlid)->value('job_id'); ´´´

13 Aug
9 months ago

rory left a reply on "Go Back" To A Route With Certain {id} In The Path.

@Vilfago thanks to the answer. I'm trying to do what you say, but how do I select with sql/model a foreign key based on the element id I have?

I tried with: ´´´ $projectid = Job_model::with('project')->get(); ´´´ but it just retrieve me all the foreign key of jobs that is not what I want.

rory started a new conversation "Go Back" To A Route With Certain {id} In The Path.

I have a project with 4 DB tables connected with one-to-many and one-to-one relation. The relations between the table are nested such as: One Project has many Jobs One Job has many URLs One Url has One content

Now I need to have a GoBack button that from URLs(with certain Job_id) redirect to all Jobs(with certain Project_id). I tried different solutions with javascript but what I got is just all the elements in the Jobs Table.

06 Aug
9 months ago

rory left a reply on Pass Id From Route To Controller.

Thanks @salmon, for me worked the second solution. The first one gives me this error:

´´´ "Missing required parameters for [Route: ] [URI: upload/{id}/file]. (View: /var/www/tcc/src/resources/views/pages/form.blade.php)" ´´´

rory left a reply on Pass Id From Route To Controller.

hi! Thanks for your answer. The GET route essentially takes the 'job_id' from the DB table 'Jobs' and pass it to the view.

the POST route takes as input a file and I need to associate the content of this file with the 'job_id' since it is its foreign key.

01 Aug
9 months ago

rory started a new conversation Pass Id From Route To Controller.

I have a route with an {id}: ´´´ Route::get('/upload/{id}', '[email protected]')->name('joburls'); ´´´ and I need this id into a controller that is associated with another route:

´´´ Route::post('/upload/file', '[email protected]_xsl'); ´´´

How can I do this?

25 Jul
10 months ago

rory started a new conversation Change Color Element On Value Change

This is my general problem: https://stackoverflow.com/questions/51285106/laravel-update-status-dots-after-successfully-executing-function-in-controller

I changed my database and added a status column and using Laravel controllers the value of the dots are successfully updated. Now I do not understand how to hide/show the correct element once the value is changed.

I tried with this but nothing happens. If I am right on page load the function should be executed...

´´´ $(document).ready(function() {

function changestatus(){ if($("span[name=status]").val() == "1"){ $(".dot-secondatry").hide(); $(".dot-success").show(); //$(".dot-secondary").css('display', 'none'); //$(".dot-success").css('display', 'inline-block'); }else{ $(".dot-secondatry").show(); $(".dot-success").hide(); } }

}); ´´´

18 Jul
10 months ago

rory left a reply on Can't Migrate A Foreign Key

Hi! I solved my problem by first empty my tables...but still the problem about FK->nullable() remain. For the moment I dropped the nullable() but I think it makes sense?

rory left a reply on Can't Migrate A Foreign Key

@Snapey I do not have the FK column because I'm trying to update my migration but I get the error above. Should I remove the FK from the model and try to update the migration before?

rory left a reply on Can't Migrate A Foreign Key

@Tray2 The problem is that I'm trying to update a table with a new column. This column should contain the FK. The table "content" has the scraped content of "url" table, but if the content is not scraped than the "url" row has no correspondence with the "content" row. How to design this kind of relationship?

rory left a reply on Can't Migrate A Foreign Key

Sorry for the mess. I updated my question.

17 Jul
10 months ago

rory started a new conversation Can't Migrate A Foreign Key

Hi! Today I tried to read a lot of similar questions but I can't understand what is wrong here.

The error message:

 SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`tcc`.`#sql-1_5e`, CONSTRAINT `job_contents_url_id_foreign` FOREIGN KEY (`url_id`) REFERENCES `job_urls` (`id`)) (SQL: alter table `job_contents` add constraint `job_contents_url_id_foreign` foreign key (`url_id`) references `job_urls` (`id`))

I have a relationship one to one between the table job_urls and job_contents. I added the relation to the models like this:

Model for job_ulrs:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Joburl_model extends Model
{
    protected $table = 'job_urls';

    protected $primaryKey = "id";

    public function jobcontent()
    {
        return $this->hasOne('App\Jobcontent_model', 'foreign_key');
    }
}

Model for job_contents

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Joburl_model extends Model
{
    protected $table = 'job_urls';

    protected $primaryKey = "id";

    public function jobcontent()
    {
        return $this->hasOne('App\Jobcontent_model', 'foreign_key');
    }
}

Then I had to run a migration since the foreign key was not present in my table. This migration worked for the integer('url_id') but not for the foreign key.

<?php

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

class AddFkToUrlcontent extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('job_contents', function(Blueprint $table) {
             $table->integer('url_id')->nullable()->unsigned()->change();
             $table->foreign('url_id')->references('id')->on('job_urls')->nullable();
          });

    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('job_contents', function(Blueprint $table) {
            $table->dropColumn('url_id');
            $table->dropForeign('url_id');
         });
    }
}

And these are my tables:

JOB_CONTENT

id int(10) unsigned Auto Increment url_id int(10) unsigned NULL title varchar(255) description text header_response json html_page_content longtext status_code varchar(255) created_at timestamp NULL

JOB_URL

id int(10) unsigned Auto Increment job_id int(11) url varchar(255) hash varchar(255) created_at timestamp NULL updated_at timestamp NULL

11 Jul
10 months ago

rory left a reply on Update Status Dots After Successfully Executing Function In Controller

HI @Sergiu17 thanks for yur answer, I see the difference but it did not change anything for my problem. I updated my question with the modified code.

It is a pity that I can't upload an image, but I have to show on my table (with green button) that the url in the specific row was crawled. The color should change after the controller function crawl() is launched. Do I need a cookie for that? I'm just guessing....

rory started a new conversation Update Status Dots After Successfully Executing Function In Controller

I have a urls table and to crawl. If the crawl is successful the function should redirect with a success message and change the color (grey to green) in correspondence of the crawled urls. The problem is that I do not manage to pass multiple data from controller to view, I tried different solutions, but didn't work.

this is my controller. 'Success' is the bootstrap success message and $arr_ids is the array with the url's ids crawled:

return redirect()->back()->with('success','Scrape completed for id '.$ids.'!')->with('arr_ids',$arr_ids);

This is my blade table:

<div class="table-responsive">
            <table class="table table-bordered table-striped">
                <thead>
                    <tr>
                        <th><input type="checkbox" name="myTextEditBox" value="" class="chk" id="checkAll"/></th>
                        <th>id</th>
                        <th>job_id</th>
                        <th>url</th>
                        <th>hash</th>
                        <th>created_at</th>
                        <th>updated_at</th>
                        <th>crawl-status</th>
                    </tr>
                </thead>
                <tbody>
                    @if(isset($urls_data))
                    @foreach($urls_data as $item)
                    <tr>
                        <td><input type="checkbox"  value="{{$item->id}}" class="check" /></td>
                        <td>{{$item->id}}</td>
                        <td>{{$item->job_id}}</td>
                        <td>{{$item->url}}</td>
                        <td>{{$item->hash}}</td>
                        <td>{{$item->created_at}}</td>
                        <td>{{$item->updated_at}}</td>
                        <td>
                            @if ($message = Session::get('success'))
                                    <span class="dot dot-success"></span>
                            @else
                                <span class="dot dot-secondary"></span>
                            @endif
                        </td>
                    </tr>
                    @endforeach
                    @endif
                </tbody>
            </table>
        </div>

04 Jul
10 months ago

rory left a reply on Navigation Bar Not Fixed On The Top Of The Page.

ok I finally got it! I had to use <nav class="navbar navbar-inverse navbar-fixed-top">

rory started a new conversation Navigation Bar Not Fixed On The Top Of The Page.

Hi!

I want a navigation bar to be the same for all my pages, therefore I included it in the master. The problem is that the navbar never shows on the top of the page but always at the bottom. The funny thing is that if I include it in each page works properly. Can't figure out what is wrong.

This is my master.blade:

<!doctype html>
<html lang="{{ app()->getLocale() }}">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link href="{{asset('css/style.css')}}" rel="stylesheet"/>

        <title>TCC - @yield('title')</title>

        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
        <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">

    </head>

    <body>
        <div id="nav-placeholder">
            @include('partials/navbar')
        </div>
            @yield('content')
    </body>

</html>

This is the navigation bar:


<nav class="navbar fixed-top navbar-inverse">
    <ul class="nav navbar-nav">
      <li><a href="#">Home</a></li>
      <li><a href="#">Projects</a></li>
      <li><a href="#">Urls</a></li>
      <li><a href="#">Urls Contents</a></li>
    </ul>
</nav>

This is the beginning of one of my pages:

@extends('layouts.master')

@section('title', 'Projects')

@section('content')

    <div class="container">
        <h3 class="jumbotron">Create here your project</h3>

        <form method="post" id="projectform" class="w3-container w3-light-grey" action={{action('[email protected]')}} enctype="multipart/form-data">
        {{csrf_field()}}
            <p>
            <label>Project Name</label>
            <input class="w3-input w3-border w3-round" name="name" type="text"></p>
            <p>
            <label>Project Description</label>
            <input class="w3-input w3-border w3-round" name="description" type="text"></p>

        <button type="submit" class="btn btn-primary" style="margin-top:10px">Create Project</button>
        </form>

rory started a new conversation Change View Folder Organization Not Got: "View [overview] Not Found."

Hi! I think I mess little bit thing up. I changed my view folder to better organize it and I moved blade to a subfolder then I also added a layout folder and a partial folder to add further blade. Now I'm not able to see any view anymore...can anyone help?

27 Jun
10 months ago

rory started a new conversation Pass Data From Laravel To [email protected]

Hi! I'm trying to build a form to edit and update my database. I want to use modal and i need to pass all data from the form to the controller in order to update the database.

Here is my controller:

public function update(Request $request)
    {
        #$projectID = \DB::table('projects')->select('id')->get(),

        try
        {
            //Find the project in Project_model
            $project = Project_model::findOrFail($request->project_id);

            //Set project object attributes
            $project->name = $request->get('name');
            $project->description = $request->get('description');

            // Save/update project.
            $project->save();

            #return view('form_project')->with('project', $project);
            return redirect()->back()->with('project', $project);
        }

        catch(ModelNotFoundException $err)
        {
            return redirect()->action('[email protected]');
        }


    }

This is the script that should pass the data regarding the project id:


//search and retrieve data from Modal
$('#editModal').on('show.bs.modal', function (event) {
     var button = $(event.relatedTarget)

     var name = button.data('myname')
     var description = button.data('mydesc')
     var project_id = button.data('projectID')

     var modal = $(this)

     //put the values in modal <input>
     modal.find('.modal-body #name').val(name);
     modal.find('.modal-body #description').val(description);
     modal.find('.modal-body #project_id').val(project_id);
})

And this is my Blade, here in the input with id=project_id the value should be full with the id of the project....but nothing is happening:

<html lang="en">
    <head>
        <title>File Upload</title>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
        <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    </head>
<body>

    <div class="container">
        <h3 class="jumbotron">Create here your project</h3>

        <form method="post" id="projectform" class="w3-container w3-light-grey" action={{action('[email protected]')}} enctype="multipart/form-data">
        {{csrf_field()}}
            <p>
            <label>Project Name</label>
            <input class="w3-input w3-border w3-round" name="name" type="text"></p>
            <p>
            <label>Project Description</label>
            <input class="w3-input w3-border w3-round" name="description" type="text"></p>

        <button type="submit" class="btn btn-primary" style="margin-top:10px">Create Project</button>
        </form>

    </div>

    <div class="container-fluid">
        <h3 class="jumbotron">Your Projects</h3>
            <div class="table-responsive">
                <table class="table table-bordered table-striped">
                    <thead>
                        <tr>
                            <th>ID</th>
                            <th>name</th>
                            <th>description</th>
                            <th>created_at </th>
                        </tr>
                    </thead>
                    <tbody>
                        @if(isset($project_data))
                        @foreach($project_data as $project)
                            <tr>
                                <td> {{$project->id}} </td>
                                <td> {{$project->name}} </td>
                                <td> {{$project->description}} </td>
                                <td> {{$project->created_at}} </td>
                                <td>
                                    <button type="button" class="btn btn-warning btn-detail open-modal"
                                    data-projectID="{{$project->id}}"
                                    data-myname="{{$project->name}}"
                                    data-mydesc="{{$project->description}}"
                                    data-toggle="modal"
                                    data-target="#editModal">Edit</button>
                                    <button class="btn btn-danger btn-delete delete-project">Delete</button>
                                    <button class="btn btn-info">See Jobs</button>
                                </td>
                            </tr>
                        @endforeach
                        @endif
                   </tbody>
               </table>
           </div>
    </div>

    <!-- Modal (Pop up when edit button clicked) -->
    <div class="modal" id="editModal" tabindex="-1" role="dialog" aria-labelledby="editModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
    <div class="modal-content">
        <div class="modal-header">
            <h3 class="modal-title" id="editModalTitle">Edit your project</h3>
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        </div>
        <form method = "post"  action={{action('[email protected]')}} enctype="multipart/form-data" id="frmSave" name="frmSave"class="form-horizontal" role="form">
        {{method_field('put')}}
        {{csrf_field()}}
        <div class="modal-body">
                <input type="hidden" name="project_id" id="project_id" value="">
                <div class="form-group">
                    <label for="name" class="col-sm-3 control-label">Project Name</label>
                    <div class="col-sm-9">
                        <input type="text" class="form-control" id="name" name="name" placeholder="" value="">
                    </div>
                </div>
                <div class="form-group">
                    <label for="description" class="col-sm-3 control-label">Description</label>
                    <div class="col-sm-9">
                        <input type="text" class="form-control" id="description" name="description" placeholder="" value="">
                    </div>
                </div>
        </div>
        <div class="modal-footer">
            <button type="submit" class="btn btn-primary" id="btn-save" value="add">Save changes</button>
            <input type="hidden" id="project_id" name="project_id" value="0">
            <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        </div>
        </form>
    </div>
    </div>
    </div>

    <script src="/js/crud.js"></script>
</body>
</html>

26 Jun
11 months ago

rory left a reply on Bootstrap Modal Not Working In Laravel?

Ok, I got it, I had to add :

rory started a new conversation Bootstrap Modal Not Working In Laravel?

I have a database table, at the end of each row gibt es a EDIT button. On click EDIT it should appear a modal. Now, I copied and pasted the code from the original website ...why it is not working???

Here my controller:

`

19 Jun
11 months ago

rory started a new conversation Display Table From Database

I have a database table filled through a form and now I would like to show the table at the end of the process. But I get the error: "Undefined variable: project_data (View: /var/www/tcc/src/resources/views/form_project.blade.php)" Why can the view not find my variable?

this is my controller:

`<?php

namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Support\Facades\Input;

class project_create extends Controller { public function showpform() { return view('form_project'); }

public function filltable(Request $request)
{
    $name = $request->input('name');
    $description = $request->input('description');

    \DB::table('projects')->insert(
        [
            'project_id' => 1,
            'name' => $rawUrl,
            'description' => $hashedUrl,
            'created_at' =>  \Carbon\Carbon::now(),
        ]);

    $project_data = \DB::table('projects')->select('*')->get();
    return View::make('form_project', compact('project_data'));
}

}`

And this is my view:

` File Upload

<div class="container">
    <h3 class="jumbotron">Create here your project</h3>

    <form class="w3-container w3-light-grey" action={{action('[email protected]')}} enctype="multipart/form-data">
    {{csrf_field()}}
        <p>
        <label>Project Name</label>
        <input class="w3-input w3-border w3-round" name="name" type="text"></p>
        <p>
        <label>Project Description</label>
        <input class="w3-input w3-border w3-round" name="description" type="text"></p>

    <button type="submit" class="btn btn-primary" style="margin-top:10px">Create Project</button>
    </form>

</div>

<table>
    <thead>
        <tr>
            <th> id</th>
            <th> name</th>
            <th> description</th>
            <th> created_at </th>
        </tr>
    </thead>
    <tbody>
         @foreach($project_data as $data)
          <tr>
              <td> {{$data->id}} </td>
              <td> {{$data->name}} </td>
              <td> {{$data->description}} </td>
              <td> {{$data->created_at}} </td>
          </tr>
         @endforeach
   </tbody>
`

Thanks for the help.

13 Jun
11 months ago

rory started a new conversation Throw New MethodNotAllowedHttpException($others);

I'm trying to upload a csv file to a form read it and store in a database. But I'm getting an empty error message that refers to: /var/www/tcc/src/vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php on the line 255: throw new MethodNotAllowedHttpException($others). Where is my problem?

These are my routes:

Route::get('/', '[email protected]'); Route::get('/scrape', '[email protected]'); Route::get('/upload','[email protected]'); Route::post('/readxsl', ['[email protected]_xsl']);

This is my blade:

File Upload

<div class="container">
<h3 class="jumbotron">File Upload</h3>

    <form method="post"  action="{{ action('[email protected]_xsl') }}"  enctype="multipart/form-data">
        {{csrf_field()}}

        <div class="input-group control-group increment" >
            <input type="file" name="filename[]" class="form-control">
        <div class="input-group-btn">
            <button type="button" class="btn btn-info"><i class="glyphicon glyphicon-plus"></i>Add</button>
        </div>
        </div>

        <button type="submit" class="btn btn-primary" style="margin-top:10px">Upload</button>

    </form>
</div>

And this is my controller:

12 Jun
11 months ago

rory left a reply on Passing String (path) From View To Controller

@Resin thanks for the answer, but I think this is the solution to pass data from the controller to view. I'm looking for the opposite. I have data uploaded in the view and I want to pass it to the controller.

rory started a new conversation Passing String (path) From View To Controller

I have a button that the user shall use to upload csv file. Then this csv is read in the controller and uploaded in a database.

This is my view:

{{csrf_field()}} Upload csv file

In my controller I just have the $path in the variable where the path to the file is stored:

public function read_xsl()
{

    $path = '../data/blog-urls-gartenbau.csv';
    if (($handle = fopen($path, "r")) !== FALSE)
    {
        while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
        {
            $num = count($data);
            for ($c=0; $c < $num; $c++)
            {
                $rawUrl = $data[$c];
                $hashedUrl = sha1($data[$c]);
                \DB::table('job_urls')->insert(
                    [
                        'job_id' => 1,
                        'url' => $rawUrl,
                        'hash' => $hashedUrl,
                        'created_at' =>  \Carbon\Carbon::now(), # \Datetime()
                        'updated_at' => \Carbon\Carbon::now(),
                    ]);
            }
        }
        fclose($handle);
    }
     return view('form');
}

Which is the best way to pass data from view to controller? Thanks for the help.

05 Jun
11 months ago

rory started a new conversation Web Scraping With Laravel: Goutte Or Guzzle?

What is the difference between Goutte and Guzzle? I did some scrap with Guzzle and I manage to get things like StatusCode, Header.

Now I need a title of the page (which is child elem of ) and I understand that to do that I need Goutte.

Is it possible to retrieve such node elements also with Guzzle?

29 May
11 months ago

rory left a reply on Populate Database In Laravel

@jurios I have another question, once you make the second migration file to populate your table how do you connect the correspondent table schema?

rory left a reply on Populate Database In Laravel

Thanks @Cronix and @jurios this is exactly what I was looking for. I think I'll also put all in my migration, the idea of two separated files would be the best solution for me.