jcmargentina

Experience

23,290

22 Best Reply Awards

  • Member Since 10 Months Ago
  • 81 Lessons Completed
  • 0 Favorites

21st April, 2018

jcmargentina started a new conversation Apache Monitor Tool (recommendations) • 3 days ago

Any good , and open source , apache and/or nginx monitoring tool and performance measure ?

20th April, 2018

jcmargentina left a reply on Updated Value Not Showed In View (Show) • 4 days ago

@tykus , excellent answer, thanks very much. EVenthough I could solve it ... the info you provided is excellent

jcmargentina left a reply on Updated Value Not Showed In View (Show) • 4 days ago

OMG .. just in case.... I fixed the "problem" ... is more like an issue I think

I change the question ,... and that fixed the issue.

instead of asking by the relationshiop .. I ask directly in the field that makes the relation ship ... even though I get the exact same value with either ,,,,, is affectng the view generation.

 if ($model->status_id == 123) {

            $model->status_id = 444;
            
            $model->save();

        }
...

jcmargentina started a new conversation Updated Value Not Showed In View (Show) • 4 days ago

I will try to explain the problem I am having.

I have a route:

/model/{model}

that calls a method in a controller to "show" the model with id = {model}

the method

public function show(MyModel $model)
    {

        if ($model->status->id == 123) {

            $model->status_id = 444;
            
            $model->save();

        }

        return view('model.show')->with('model', $model);
    }

in the view "model.show" ... I get the value in "$model" ... and I display the value of "$model->status->name" ... so basically

  1. I call the url to show info regarding certain model
  2. if that model->status->id == 123 ... then I change it to 444 and save the change in the model
  3. I call the view and I pass the model to that view

the thing is ....

if model has status 123 ... I execute the change OK (is saved in DB correctly) ... but in the view ... I still see the name of status 123 ... NOT 444.

If I refresh the page .. I get the right name.

It is like is sending me the view before the change in DB is done. or something like that.

Any clue?

18th April, 2018

jcmargentina left a reply on How To Create New Option Value Without Page Refreshing With Ajax? • 6 days ago

change the success of your ajax call to:

assuming your form id is = "frmTest"

 success: function(data){
                $(form#frmTest select#viedo_label).append('<option selected="true" value="'+data.id+'">'+data.name+'</option>');
            },

jcmargentina left a reply on How To Create New Option Value Without Page Refreshing With Ajax? • 6 days ago

wow I did not see the form inside the form ... thanks @Cronix

jcmargentina left a reply on How To Create Form With Ajax? • 6 days ago

or try this in the script tag at the end too

$('#frmTest').on('submit',function(e){
        e.preventDefault();

        var name = $('#name').val();
        var label = $('#viedo_label');
        label.empty();
        var op = "";
        $.ajax({
            type:"POST",
            url:"{{route('videog.store')}}",
            data:{'name':name,
                    '_token':{{csrf_token()}}
                },
            dataType: 'json',
            success: function(data){
                alert("OK");
                op+='<option selected="true" value="'+data.id+'">'+data.name+'</option>';
            },
            label.html(op);
            error: function(data){
                alert("ERROR");
            }

        })
        $('#name').empty();
    });

in both codes check my changes

jcmargentina left a reply on How To Create Form With Ajax? • 6 days ago

<form id="frmTest" action="{{route('video.store')}}" enctype="multipart/form-data" method="post">
        {{ csrf_field() }}

        <div class="form-group">
            
            <input type="file" name="file[]" multiple>
        </div>



        <div class="form-group">

            <label>Choose Viedo-Group</label>
            <select id='viedo_label' name="viedo_label" class="form-control">

                <option value="0" disabled="true" selected="true">--Select--</option>
                @foreach($vgroup as $key => $value)

                <option value= "{{ $key }}" > {{$value}}</option>

                @endforeach

            </select>
            
        </div>
            


            <form id="save">
                <input id="name" type="text" name="name">
                <button id="create">Create</button>
            </form>



        
        <br><br>
        
        <button type="submit" class="btn btn-primary">Submit</button>
        <a href="{{route('class.index')}}" class="btn btn-default">Cancel</a>

    </div>
</div>
</form>
</div>
<script>
$(function() { 
    $('#frmTest').on('submit',function(e){
        e.preventDefault();

        var name = $('#name').val();
        var label = $('#viedo_label');
        label.empty();
        var op = "";
        $.ajax({
            type:"POST",
            url:"{{route('videog.store')}}",
            data:{'name':name,
                    '_token':{{csrf_token()}}
                },
            dataType: 'json',
            success: function(data){
                alert("OK");
                op+='<option selected="true" value="'+data.id+'">'+data.name+'</option>';
            },
            label.html(op);
            error: function(data){
                alert("ERROR");
            }

        })
        $('#name').empty();
    });
});
</script>

I did not check your controller , only the html and javascript.

jcmargentina left a reply on Display The Nom Not The Id • 6 days ago

replace the javascript function you showed us before:

function getTechniciensByTarification(val) {
  if(val.length>0) {
    var tarificationtache_id = val;
$.get(getgetTechniciensByTarificationUrl+'/'+tarificationtache_id,function(res) {      

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

     });
 }
}

or if it does not work try

function getTechniciensByTarification(val) {
  if(val.length>0) {
    var tarificationtache_id = val;
$.get(getgetTechniciensByTarificationUrl+'/'+tarificationtache_id,function(res) {      

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

     });
 }
}

are you sure the "nom" column exists in the DB right for the technicien tables ?

jcmargentina left a reply on How To Pass Value To Bootstrap Modal Window ? • 6 days ago

glad to know you got it ... but the

<input type="hidden" name="id" value"">

is redundant ... you dont need it at all.

I think we already achieve your petition a while ago my friend.

jcmargentina left a reply on Display The Nom Not The Id • 6 days ago

did you try this?

html+='<option value="'+item.id+'">'+item.nom+'</option>';

jcmargentina left a reply on Got This Error "htmlspecialchars() Expects Parameter 1 To Be String, Object Given" When I Try To Json_decode In Blade File • 6 days ago

debug with this code please

@foreach($history as $key => $modify)

<?php
    var_dump($modify);
?>

                  
@endforeach 

jcmargentina left a reply on Display The Nom Not The Id • 6 days ago

Go to the file :

app\Http\Controllers\TechnicienController

and share the function

getTechniciensByTarificationtache

17th April, 2018

jcmargentina left a reply on Got This Error "htmlspecialchars() Expects Parameter 1 To Be String, Object Given" When I Try To Json_decode In Blade File • 1 week ago

try this

@forelse($history as $key => $modify)

                            <li class="list-group-item">

                                <div class="level">

                                    <tr>
                    <?php 
                        $before = json_decode($modify->before)
                        $ttitle = $before->title;
                    ?>
                                        <td> {{ $title }} </td>
                    <!-- 
                        or you could just do 
                        {{ $before->title  }}
                        or
                        {{ $before->slug  }}
                    -->

                                    </tr>


                                </div>

                            </li>

                        @empty

                            <strong>There is no updates for this thread </strong>

                        @endforelse

jcmargentina left a reply on How To Pass Value To Bootstrap Modal Window ? • 1 week ago

thanks for the code ... ok lets debug

open chrome

then press F12 it will open the developer tools.

RELOAD the page with the developer tools open ... and go into the "Console" tab ... and check for some errors there .

If there are no errors ... continue ..

go to the network Tab, and check the Preserve Log checkbox on it ... then press the delete button on some item on your list ... the modal should open .. did open ? ... if yes ... delete!

you will see that some content starts apearing .... thats your netwrk traffic generated by the website through your browser.

examine the request made (specially the URL where you are sending the request to ) and the response you get from the server.

please check all this and share.

PD: when the modal pops up ... right click it ... and choose "INSPECT" ... see the ... and check the "action" is right too .

jcmargentina left a reply on How To Pass Value To Bootstrap Modal Window ? • 1 week ago

try this code in your view, do no separate the JS to another file, keep it in the view.

<div class="modal fade" id="deleteModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">Delete Company</h4>
            </div>
            <div class="modal-body">
                    Are you sure you want to delete?
            </div>
            <div class="modal-footer">
                <form id="userForm" action="" method="post">
                    @csrf
                    @method('DELETE')
                    <input type="hidden" name="id">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    <button type="submit" class="btn btn-danger">Delete</button>
                </form>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
$('#deleteModal').on('show.bs.modal', function (event) {
    var button = $(event.relatedTarget);
        var id = button.data('id');

    $('#userForm').attr("action", "{{ url('/companies') }}" + "/" + id);
});
</script>

please make sure Jquery is loaded before this.

Give some feedback

jcmargentina left a reply on Display The Nom Not The Id • 1 week ago

that is specifically to your code.

you need to modify the code that is executed when you make a request to that url ... the one formed by resolving

"getgetTechniciensByTarificationUrl+'/'+tarificationtache_id"

at least find that piece of code and share that piece of code here and I will be glad to help you out.

jcmargentina left a reply on Display The Nom Not The Id • 1 week ago

your problem is in the function "getTechniciensByTarification" specifically at :

html+='<option value="'+item.id+'">'+item.technicien_id+'</option>';

as you can see you decide to show the "item.technicien_id" ... id instead of the name.

but ... that set of results come from an ajax request you make to "getgetTechniciensByTarificationUrl+'/'+tarificationtache_id"

so go into your code, see the web.php file and go to the function/[email protected] that handles that request.

you need to add the technicien name manually in the result returned from that function/[email protected]

jcmargentina left a reply on How To Pass Value To Bootstrap Modal Window ? • 1 week ago

Man i wrote the code for you. at least use it first and then try to edit it.

your javascript is wrong .... again.

check the code you gave us. tjen use mine. and ser results

16th April, 2018

jcmargentina left a reply on Axios.put Retriving "500 (Internal Server Error)" • 1 week ago

I think you need to send a CSRF token

you can render one using blade , like {{ csrf_token() }}

jcmargentina left a reply on Laravel Route Through Ajax Through Error 500 • 1 week ago

I think you need a CSRF TOKEN for that request my friend.

you can render one in your view using {{ csrf_token() }}

$.post('{{url('like')}}',{
        userId:userIdLiked, 
        postId:postIdLiked,
        _token: "{{ csrf_token() }}"
    },  
    function ($data) {
        $('.like-count').html($data);
    }
);

jcmargentina left a reply on How To Pass Value To Bootstrap Modal Window ? • 1 week ago

change the modal to

<div class="modal fade" id="deleteModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">Delete Company</h4>
            </div>
            <div class="modal-body">
                    Are you sure you want to delete?
            </div>
            <div class="modal-footer">
                <form id="userForm" action="" method="post">
                    @csrf
                    @method('DELETE')
                    <input type="hidden" name="id">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    <button type="submit" class="btn btn-danger">Delete</button>
                </form>
            </div>
        </div>
    </div>
</div>

add this javascript somewhere at the end:

$('#deleteModal').on('show.bs.modal', function (event) {
    var button = $(event.relatedTarget);
        var id = button.data('id');

    $('#userForm').attr("action", "{{ url('/companies') }}" + "/" + id);
})

please gvie me a feedback on this as I am writting form my phone

jcmargentina left a reply on Eager Loading With Use Of Related Model's Scope • 1 week ago

updates ?

jcmargentina left a reply on Eager Loading With Use Of Related Model's Scope • 1 week ago

I believe the problem could be the column name in the table for your images.

the main column is called imageId ... and laravel expects it to be called just "id".

what columns do you have in the DB table related with the Image Class ?

jcmargentina left a reply on Efficiently Setting A Password Verification Before Accessing A Certain View • 1 week ago

yes, that is a great advice

jcmargentina left a reply on Session Doesnt Work In FIREFOX • 1 week ago

Open an anonymous navigation TAB in firefox, and check again there. Let me know

jcmargentina left a reply on Session Doesnt Work In FIREFOX • 1 week ago

Do you allow cookies ? check your broswer preferences

Also ... do you have firebug extension installed ? well, ... it may cause troubles too.

15th April, 2018

jcmargentina left a reply on Repository Pattern • 1 week ago

  1. Probably I dont get the task right, but are you sure about this ? (see my comments)
/* 

Are you sure you have to ask for >= ... and not <= ???

        ['created_at', '<=', now()->subDays($establishment->days_retention)],
*/

public function getExpiredVisitorsForEstablishment(Establishment $establishment)
    {
        return $this->model->where([
        ['created_at', '>=', now()->subDays($establishment->days_retention)],
                ['establishment_id', '=', $establishment->id],
        ])->get();
    }
  1. I would avoid the delete call inside the loop, is better to call it once
public function deleteExpiredVisitors()
    {
        $visitors = (new VisitorRepository)->getExpiredVisitorsForEstablishment($this);

        $visitors->each(function ($visitor) {
            $visitor->delete();
        });
    }

for something like

public function deleteExpiredVisitors()
    {
    /* Assuming the is a Visitor Model for visitors */
    /* what out the >= */

       \App\Visitor::where('created_at', '>=', now()->subDays($this->days_retention))->where('establishment_id', '=', $this->id)->delete();
    }

14th April, 2018

jcmargentina left a reply on Best Practice? Using 'auth()->user()' Or '$user = Auth()->user()'? • 1 week ago

@Helmchen , probably, if someone can provide info related, I would appreciate

jcmargentina left a reply on Best Practice? Using 'auth()->user()' Or '$user = Auth()->user()'? • 1 week ago

Is the same result, but I have my doubts if its "the same for php" unless php has some cache inside it.

please correct me if I am wrong:

Whe PHP resolves this expression "auth()->user()" , basically what happens :

  1. resolves auth()
  2. take the result in 1) and execute the "user()" method on it
  3. return result obteined in 2)

so if I have in my code "auth()->user()" over and over again I would have the 3 steps over and over again.

But if we assign $user = auth()->user() , to a variable, you already have those 3 steps done.

That is why even though you get the same result, ... is not the same for PHP in terms of performance execution.

please, correct me if I am wrong, interesting subject.

jcmargentina left a reply on Best Practice? Using 'auth()->user()' Or '$user = Auth()->user()'? • 1 week ago

use the $user variable if you are going to call auth()->user()** more than once.

why ? .. think about it.

lets say that in a function you have a call to atuh()->user()->* (where * is whatever) ... well ... how PHP will resolve that??

It will go step by step (-> by ->) ... so ... now imagine you have more than one call to auth()->user()->** , well , PHP will have to resolve those expressions over and over again, .......... if you are looking for performance ... use the $user variable containing auth()->user() result inside it.

13th April, 2018

jcmargentina left a reply on Tips For Building A FAST Restfull API With Laravel • 1 week ago

bro. something os wrong. it cannot take forever yo get 10 items.

best thing to do .... debug

jcmargentina left a reply on Cannot Login • 1 week ago

Bro, your website is extremely unsecure

I could login in 3 seconds just like that.

The DEBUG is activated, turn it off!

you are using GET method in the login form !

follow the standards or you will have problems ... serious ones in the future

jcmargentina left a reply on Laravel - Save Form Data • 1 week ago

you can use sessions

you can have the all sections in one page, and pass from one to another with javascript effect, and then , upload everything at once (recommended)

you can go from 1 section to another (at different urls), passing data from section 1 to 2, using url parameters (of course ... data needs to be small , not overflow the standards for URLs

12th April, 2018

jcmargentina left a reply on Laravel . Frontend Framework Needed Or No? • 1 week ago

even if you need to get a mobile version ... you can achieve a mobile version with html + css.

using bootstrap in the right way ... will give you automatically that result for example.

jcmargentina left a reply on Laravel Middleware • 1 week ago

excuse my ignorance , but that "Signed" Middleware, is a Laravel native middleware ? where is the information about it ?

jcmargentina left a reply on Laravel Scheduler Writes Log With Wrong Permission • 1 week ago

the scheduled job is done with a cron job ?

11th April, 2018

jcmargentina left a reply on Why My Laravel Website Is So Slow? • 1 week ago

are you using php7 ? .... you should .... you must.

Also .... use PHP-FPM and not php as a module for your webserver

in your db .... if SQL. ... use indexes wherever you need to speed Up queries.

those tips will increase processing speed in the server .... speeding Up the response time

jcmargentina left a reply on Problem On "php Artisan Serve " • 1 week ago

what is the problem?

10th April, 2018

jcmargentina left a reply on How To Show A Section With Name And Surname Fields Only If Column "collect_data_from_participants" Is 1? • 2 weeks ago

we dont know all your code , so pretty much we have to guess.

the function storeQuantity should be called with an ID ... the ID of the congress we are buying the tickets for. Either in the $request or explicit ... you could pass that ID to the function.

Then ... when you call the congresses.registration view ... do something like (asuming

        public function storeQuantity(Request $request){
            $typeQuantities = $request->get('types');
        
    /* consider to edit the code for your convenience */    
    $congress = \App\Congress::findOrFail($request->input('congress_id'));

            foreach($typeQuantities as $typeName => $quantity){
                $type = TicketType::where('name', $typeName)->firstOrFail();
                $price = $type->price;
                $selectedTypes[$type->name]['quantity'] = $quantity;
                $selectedTypes[$type->name]['price'] = $price;
            }
            return view('congresses.registration')->with('selectedTypes', $selectedTypes)->with('congress', $congress);
        }

later in the next view ... you can consult the data of that congress doing something like (Blade)

    @if (!empty($congress))
        @if ($congress->collect_data_from_participants == 0)
            <!-- HTML CODE when collect_data_from_participants = 0 -->
        @endif

        @if ($congress->collect_data_from_participants == 1)
            <!-- HTML CODE when collect_data_from_participants = 0 -->
        @endif
    @endif

something like that

jcmargentina left a reply on How Can I Pass Variable As Query String In Laravel • 2 weeks ago

or for the current loged in user

<a href="{{route('posts.show', auth()->user ()->id)}}"><button name="home">Home</button></a>

jcmargentina left a reply on How Can I Pass Variable As Query String In Laravel • 2 weeks ago

Route::get('/user/post/{id?}', '[email protected]');

I dont know your exact code, but here you can send a parameter to the show method inthe PostController controller called "id" that is optional, so it can be null too if you ommit it, if you dont want that behaviour just remove the "?" from it

jcmargentina left a reply on Why My Laravel Website Is So Slow? • 2 weeks ago

maybe you could mix regular request with AJAX, so you get the website ASAP ... and then you can load second instances resources.

but ... honestly, ... your website is really cool, and loads really fast (even though my internet connection sucks), congrats!

jcmargentina left a reply on Why My Laravel Website Is So Slow? • 2 weeks ago

compress images as much as you can without loosing quality

Edit Your Profile
Update

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