SIGN IN / SIGN UP


Recent posts

Don't miss the latest trends

  • search controller

    coders guild

    search controller

    public function posts_search(Request $request) { $search = $request->input('query'); $posts = Post::where('title', 'LIKE', "%{$search}%") ->orWhere('description', 'LIKE', "%{$search}%") ->get(); return view('user.search', compact('posts', 'search')); } Route::get('/posts_search', [UserController::class, 'posts_search'])->name('posts.search');


  • search

    coders guild

    search

    <div class="container mt-4"> <h2>Search Posts</h2> <!-- Search Form --> <form action="{{ route('posts.search') }}" method="GET" class="mb-4"> <div class="input-group"> <input type="text" name="query" class="form-control" placeholder="Search by title or description" value="{{ request('query') }}" required> <button class="btn btn-primary" type="submit">Search</button> </div> </form> @if(isset($search)) <p>Showing results for: <strong>{{ $search }}</strong></p> @endif <!-- Search Results Table --> <table class="table table-bordered table-striped"> <thead class="thead-dark"> <tr> <th>ID</th> <th>Title</th> <th>Description</th> </tr> </thead> <tbody> @forelse ($posts as $post) <tr> <td>{{ $post->id }}</td> <td>{{ $post->title }}</td> <td>{{ $post->description }}</td> </tr> @empty <tr> <td colspan="3" class="text-center">No results found.</td> </tr> @endforelse </tbody> </table> </div>


  • controller no ref

    coders guild

    controller no ref

    public function post_store(Request $request) { $request->validate([ 'title' => 'required|string|max:255', 'description' => 'required|string', ]); $post = Post::create($request->only('title', 'description')); // Return JSON for AJAX return response()->json($post); }


  • js noref

    coders guild

    js noref

    <script> $(document).ready(function() { $('#createPostForm').submit(function(e) { e.preventDefault(); // prevent default form submission let formData = $(this).serialize(); $.ajax({ url: "{{ route('posts.store') }}", method: "POST", data: formData, success: function(response) { // Close modal $('#createModal').modal('hide'); // Reset form $('#createPostForm')[0].reset(); // Optionally show success message alert('Post added successfully!'); // Append the new post to the table $('tbody').append(` <tr> <td>${response.id}</td> <td>${response.title}</td> <td>${response.description}</td> <td> <button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#editModal${response.id}"> Edit </button> <form action="/posts/${response.id}" method="POST" style="display: inline-block;" onsubmit="return confirm('Are you sure you want to delete this post?');"> @csrf <input type="hidden" name="_method" value="DELETE"> <button type="submit" class="btn btn-danger">Delete</button> </form> </td> </tr> `); }, error: function(xhr) { alert('Error adding post.'); } }); }); }); </script> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>


  • norefresh ui

    coders guild

    norefresh ui

    <form id="createPostForm"> @csrf <div class="modal-header"> <h5 class="modal-title" id="createModalLabel">Add New Post</h5> <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> </div> <div class="modal-body"> <div class="mb-3"> <label class="form-label">Title</label> <input type="text" class="form-control" name="title" required> </div> <div class="mb-3"> <label class="form-label">Description</label> <textarea class="form-control" name="description" rows="3" required></textarea> </div> </div> <div class="modal-footer"> <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button> <button type="submit" class="btn btn-success">Add Post</button> </div> </form>


Popular Posts

Follow Pages

  • “ Gosh jaguar ostrich quail one excited dear hello and bound and the and bland moral misheard roadrunner “
    Jane Cooper

    Jane Cooper

  • “ Gosh jaguar ostrich quail one excited dear hello and bound and the and bland moral misheard roadrunner “
    Katen Doe

    Katen Doe

  • “ Gosh jaguar ostrich quail one excited dear hello and bound and the and bland moral misheard roadrunner “
    Barbara Cartland

    Barbara Cartland