Ad

What The Url Code Can Be Write In The View File To Call The Function In Laravel Controller?

- 1 answer

$('#calendar').fullCalendar({
            events: JSON.parse(json_events),
            //events: [{"id":"14","title":"New Event","start":"2015-01-24T16:00:00+04:00","allDay":false}],
            utc: true,
            header: {
                left: 'prev,next today',
                center: 'title',
                right: 'month,agendaWeek,agendaDay'
            },
            editable: true,
            droppable: true, 
            slotDuration: '00:30:00',
            eventReceive: function(event){
                var title = event.title;
                var start = event.start.format("YYYY-MM-DD[T]HH:mm:SS");
                $.ajax({
                    url: 'process.php',
                    data: 'type=new&title='+title+'&startdate='+start+'&zone='+zone,
                    type: 'POST',
                    dataType: 'json',
                    success: function(response){
                        event.id = response.eventid;
                        $('#calendar').fullCalendar('updateEvent',event);
                    },
                    error: function(e){
                        console.log(e.responseText);

                    }
                });
                $('#calendar').fullCalendar('updateEvent',event);
                console.log(event);
            },

This is the code that i found online about, i dont understand abou the url part .Because i am using the Laravel, i not sure what to write in the url part. I have create a controller and model, just not sure how to pass the data into in and store in database.

This is the process.php can this transform into controller and model?

$type = $_POST['type'];

if($type == 'new')
{
    $startdate = $_POST['startdate'].'+'.$_POST['zone'];
    $title = $_POST['title'];
    $insert = mysqli_query($con,"INSERT INTO calendar(`title`, `startdate`, `enddate`, `allDay`) VALUES('$title','$startdate','$startdate','false')");
    $lastid = mysqli_insert_id($con);
    echo json_encode(array('status'=>'success','eventid'=>$lastid));
}

if($type == 'changetitle')
{
    $eventid = $_POST['eventid'];
    $title = $_POST['title'];
    $update = mysqli_query($con,"UPDATE calendar SET title='$title' where id='$eventid'");
    if($update)
        echo json_encode(array('status'=>'success'));
    else
        echo json_encode(array('status'=>'failed'));
}

if($type == 'resetdate')
{
    $title = $_POST['title'];
    $startdate = $_POST['start'];
    $enddate = $_POST['end'];
    $eventid = $_POST['eventid'];
    $update = mysqli_query($con,"UPDATE calendar SET title='$title', startdate = '$startdate', enddate = '$enddate' where id='$eventid'");
    if($update)
        echo json_encode(array('status'=>'success'));
    else
        echo json_encode(array('status'=>'failed'));
}

if($type == 'remove')
{
    $eventid = $_POST['eventid'];
    $delete = mysqli_query($con,"DELETE FROM calendar where id='$eventid'");
    if($delete)
        echo json_encode(array('status'=>'success'));
    else
        echo json_encode(array('status'=>'failed'));
}

if($type == 'fetch')
{
    $events = array();
    $query = mysqli_query($con, "SELECT * FROM calendar");
    while($fetch = mysqli_fetch_array($query,MYSQLI_ASSOC))
    {
    $e = array();
    $e['id'] = $fetch['id'];
    $e['title'] = $fetch['title'];
    $e['start'] = $fetch['startdate'];
    $e['end'] = $fetch['enddate'];

    $allday = ($fetch['allDay'] == "true") ? true : false;
    $e['allDay'] = $allday;

    array_push($events, $e);
    }
    echo json_encode($events);
}


?>
Ad

Answer

Here is the my logic for Laravel.

routes.php





     Route::get('/', function() {
                return View::make('hello');
        });

        Route::get('calender', '[email protected]');
        Route::post('calendar/add', '[email protected]');

Controller : CalendarController.php


    class CalendarController extends BaseController {

        function showEvent() {
            return View::make('display_event');
        }

        function postAdd() {
            echo json_encode($_POST);
        }

    }


View Script: display_event.php Download View : Click Here

Please compare html with http://192.241.236.31/themes/preview/smartadmin/1.4.1/ajaxversion/#ajax/calendar.html (Ajax calender view)

View load by ajax : http://192.241.236.31/themes/preview/smartadmin/1.4.1/ajaxversion/ajax/calendar.html

Hope this will work for You.

Ad
source: stackoverflow.com
Ad