Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x

Laravel

Laravel is a free, open-source PHP web application framework for the development of web applications following the model–view–controller (MVC) architectural pattern. Some of the features of Laravel are a modular packaging system with a dedicated dependency manager, different ways for accessing relational databases, utilities that aid in application deployment and maintenance, and its orientation toward syntactic sugar. Laravel is regarded as one of the most popular PHP frameworks.

Share tech news, updates, or what's on your mind.

Sign up to Post

Hi,
I have a datatables table I am using to allow a person to resort the row order of the slides (see attached as example). In my mysql table I am using an additional column to set the row order of each row.
So essentially in mysql I have
id - primary auto increment
SlideOrder - I am using for the sequence
SlideTitle
and a couple created/modified datetime etc.

 
table example
When the user drops a row into place the code I'm using is below to send to server ( I start getting sketchy here on in):

oTable.on( 'row-reorder', function ( e, diff, edit ) 
{
var result;
var sendloop = [];
 		
	for ( var i=0, ien=diff.length ; i<ien ; i++ )
	{
		var rowData = oTable.row( diff[i].node ).data();
		result = ''+diff[i].newData+','+diff[i].oldData+'';
		sendloop.push(result);
	}
        	
	var jsonString = JSON.stringify(sendloop);
   
$.ajax({
        type: "GET",
        url: "/dealboxx/ohs/admin/sort",
        data: {data : jsonString}, 
        cache: false
    });
    });

Open in new window


The result of which sends an ajax request and the data variable (when I drag row 1 below row 4 for example):
data["1,2","2,3","3,4","4,1"]

Had I dragged row 2 below row 3 initially I'd be sending:
data["2,3","3,2"]

Had I dragged row 3 in front of row 1:
data["1,3","2,1","3,2"]

When the data gets to my server (my wrong code) does this:
public function sortCourse(Request $request)
    {
	$obj = json_decode($request->input('data'), true);
	
	foreach($obj as $row)
	{
     
		$insertArray = explode(",",$row);
		
		$slidechange = DB::table('ohs_courses_content')
			->select('id')
			->where('SlideOrder',$insertArray[1])
		    ->first();
		
    
	DB::table('ohs_courses_content')
            ->where('id', $slidechange->id)
            ->update(['SlideOrder' => $insertArray[0]]);
 	 	}
	
    
    }

Open in new window


Depending on what I initially dragged it may work (if I'm dragging down or up). Couple drags into it and its a mess.

So my logic etc is no doubt totally wrong.

any help would be very much appreciated as always.
tj
0
Free Tool: Subnet Calculator
LVL 11
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

I want to display message with ajax  :
but i have this error in the console :
Cannot use 'in' operator to search for 'length' in L'email ou le mot de passe est incorrect.

Function Ajax
<script type="text/javascript">
   $(document).ready(function() {
        $(".login-btn").click(function(e){
             e.preventDefault();


            var _token = $("input[name='_token']").val();
            var email = $("input[name='email']").val();
            var password = $("input[name='password']").val();


            $.ajax({
                url: "/login",
                type:'POST',
                cache: false,
                data: {_token:_token,email:email, password:password},
                dataType: "json",
                success: function(data) {
                    if($.isEmptyObject(data.error)){
                        window.location = 'home';
                    }else{
                        // $(".print-error-msg").find("ul").html('');
                        // $(".print-error-msg").css('display','block');
                        // $.each( data, function( key, value ) {
                        //     $(".print-error-msg").find("ul").append('<li>'+data.error+'</li>+');
                        // });
                        printErrorMsg (data.error);

                    }
                },
                error: function(response){
                    $(".print-error-msg").find("ul").html('');
                    

Open in new window

0
I have 5 tables namely product, category, price, inventory and image.

In my product table I have a foreign key column (category_id_fk) referencing to category table primary key column (id). In my product model I have the following function defined:

    public function price(){
		return $this->hasOne('App\Models\Price','product_id_fk');
    }
	
    public function inventory(){
		return $this->hasOne('App\Models\Inventory','product_id_fk');
    }
	    
    public function image(){
		return $this->hasMany('App\Models\Image','product_id_fk');
    }
	
    public function category(){
                return $this->belongsTo('App\Models\Category','id');
    }

Open in new window



In my category model I have the following function defined:

      public function product(){
		return $this->hasMany('App\Models\Product','category_id_fk');
      }

Open in new window


I have performed the following query:

$product = Product::with('price','inventory','image')->get();

Open in new window


The result is it return all records that exist in the product table and associated tables (price, inventory, image) which is correct.

However when I attempt to perform similar action by including the category table

$product = Product::with('category','price','inventory','image')->get();

Open in new window


The result is it return all records that exist in the product table and associated tables (price, inventory, image) but the category record is incorrect (either null or unrelated record).
incorrect.txt
0
We are currently running a laravel 5.3 site using php 5.6 and would like to use caffeine for those users who insist on leaving forms open  on their devices for extended periods of time.
Unfortunately, it seems that the only version of caffeine I can find to install requires php 7.0, which we will not be prepared to upgrade to for some time.
Does anyone have a workaround?
Thanks!
0
We need a website for offering jobs and recruitment just like this one https://www.bayt.com
there are different ways to do that. we can develop our own frame work for it or we can use open source for the backend and maybe tamplates for the front end.
I want you to analyse this project requirements .
Please help me to find the requirements for this project.
0
ErrorException in Macroable.php line 74:
Method appends does not exist. (View: C:\xampp\htdocs\elasticsearch\resources\views\presult.blade.php) (View: C:\xampp\htdocs\elasticsearch\resources\views\presult.blade.php)

foreach($books as $key => $value)

            <article class="one-third">
              <figure><a href="#" title=""><img src="{{ $value['photo_url'] }}" alt="" style="height: 215px!important;" /></a></figure>

              <div class="details">
           
                <h3>{{ $value['name'] }}
                  <span class="stars">{{ $value['class'] }} 
                    <i class="material-icons">&#xE838;</i>
                    <i class="material-icons">&#xE838;</i>
                    <i class="material-icons">&#xE838;</i>
                    <i class="material-icons">&#xE838;</i>
                  </span>
                </h3>
                <span class="address">{{ $value['city_hotel'] }},{{ $value['address'] }}  <a href="hotel?query={{ $value['name'] }}">Show on map</a></span>
                <span class="rating">{{ $value['preferred'] }}</span>
                <span class="price">Max rate  <em>$ {{ $value['maxrate'] }}</em> </span>
                <span class="price">Min rate  <em>$ {{ $value['minrate'] }}</em> </span>
                <div class="description">
                  <p>{{ $value['desc_en'] }}<a href="hotel.html">More info</a></p>
                </div>   
                <a href="{{ $value['hotel_url'] }}" 

Open in new window

0

Laravel

Laravel is a free, open-source PHP web application framework for the development of web applications following the model–view–controller (MVC) architectural pattern. Some of the features of Laravel are a modular packaging system with a dedicated dependency manager, different ways for accessing relational databases, utilities that aid in application deployment and maintenance, and its orientation toward syntactic sugar. Laravel is regarded as one of the most popular PHP frameworks.

Top Experts In
Laravel
<
Monthly
>